Created
June 7, 2013 04:21
-
-
Save ruseel/5727052 to your computer and use it in GitHub Desktop.
boundedexecutor
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 BoundedExecutorService { | |
BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(4); | |
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); | |
private ExecutorService executorService = new ThreadPoolExecutor(2, 2, 0L, TimeUnit.MILLISECONDS, | |
blockingQueue, rejectedExecutionHandler); | |
public void execute(Runnable command) { | |
executorService.submit(command); | |
} | |
public void shutdown() { | |
try { | |
executorService.awaitTermination(60, TimeUnit.MINUTES); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice