protected ExecutorService createThreadPool(int min_threads,
int max_threads, long keep_alive_time, String rejection_policy,
BlockingQueue<Runnable> queue, final ThreadFactory factory) {
ThreadPoolExecutor pool = new ThreadManagerThreadPoolExecutor(
min_threads, max_threads, keep_alive_time,
TimeUnit.MILLISECONDS, queue);
pool.setThreadFactory(factory);
// default
RejectedExecutionHandler handler = new ThreadPoolExecutor.CallerRunsPolicy();
if (rejection_policy != null) {
if (rejection_policy.equals("abort"))
handler = new ThreadPoolExecutor.AbortPolicy();
else if (rejection_policy.equals("discard"))
handler = new ThreadPoolExecutor.DiscardPolicy();
else if (rejection_policy.equals("discardoldest"))
handler = new ThreadPoolExecutor.DiscardOldestPolicy();
}
pool.setRejectedExecutionHandler(new ShutdownRejectedExecutionHandler(
handler));
return pool;
}