Last active
May 27, 2019 17:52
-
-
Save Shivamdhuria/4566233eb5edd4f7265b08c6eefdf93d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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