Skip to content

ameetnaik/java-concurrent-thread-manager

Repository files navigation

Java Thread Pool Manager

Usage

Create a List of Callable tasks

	
	import java.util.concurrent.Callable;

	public class Task implements Callable<String> {

		@Override
		public String call() throws Exception {	
			// implement code to run concurrently
			return "";
		}
	}
	
	List<Task> taskList = new ArrayList<Task>();
	taskList.add(new Task());
	taskList.add(new Task());
	taskList.add(new Task());
	
	ThreadPoolManager threadPoolManager = new ThreadPoolManager();
	threadPoolManager.setTaskList(taskList);
	threadPoolManager.runManager();

Controlling number of threads

	ThreadPoolManager threadPoolManager = new ThreadPoolManager(20);

	// OR
	
	threadPoolManager.setPoolSize(20);	

Controlling messaging after threads complete

	ThreadPoolManager threadPoolManager = new ThreadPoolManager();
	threadPoolManager.setCallback(new Callable<String>(){
		@Override
		public String call() throws Exception {	
			// implement code to be called when threads are done running
			System.out.println("Thread done.");
			return "";
		}
	});

Contributor

Ameet Naik

License

MIT License