Skip to content

Instantly share code, notes, and snippets.

@Shivamdhuria
Last active May 27, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shivamdhuria/4566233eb5edd4f7265b08c6eefdf93d to your computer and use it in GitHub Desktop.
Save Shivamdhuria/4566233eb5edd4f7265b08c6eefdf93d to your computer and use it in GitHub Desktop.
public class Manager {
private static final int CORE_POOL_SIZE = 5;
private static final int MAX_POOL_SIZE = 10;
private static final int KEEP_ALIVE_TIME = 50;
private static Manager managerInstance = null;
//Queue for all the Tasks
final BlockingQueue<Runnable> WorkQueue;
private final ThreadPoolExecutor threadPoolExecutor;
static {
/*
Static instance of Manager
*/
managerInstance = new Manager();
}
/*
Make sure Manager is a SingleTon Hence private;
*/
private Manager() {
WorkQueue = new LinkedBlockingQueue<Runnable>();
threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME,
TimeUnit.MILLISECONDS, WorkQueue);
}
public void runTask(Runnable runnable) {
threadPoolExecutor.execute(runnable);
}
public static Manager getManagerInstance() {
return managerInstance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment