Skip to content

Instantly share code, notes, and snippets.

@ruseel
Created June 7, 2013 04:21
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 ruseel/5727052 to your computer and use it in GitHub Desktop.
Save ruseel/5727052 to your computer and use it in GitHub Desktop.
boundedexecutor
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();
}
}
}
@chuanwang66
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment