List of utility methods to do Thread Executor Create
ScheduledExecutorService | createStatisticsExecutor() create Statistics Executor return Executors.newScheduledThreadPool(Integer.getInteger(ORG_EHCACHE_STATISTICS_EXECUTOR_POOL_SIZE, 1), new ThreadFactory() { private AtomicInteger cnt = new AtomicInteger(0); @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, "Statistics Thread-" + cnt.incrementAndGet()); t.setDaemon(true); return t; ... |
ThreadFactory | createThreadFactory(final String prefix) create Thread Factory return new ThreadFactory() { private final ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory(); private int i = 0; @Override public Thread newThread(Runnable r) { Thread t = this.defaultThreadFactory.newThread(r); t.setName(prefix + " #" + this.i); this.i++; ... |
ExecutorService | getExecutor() Gets an existing cached thread pool or creates new one if none exists if (executor == null) { executor = Executors.newCachedThreadPool(); return executor; |
ExecutorService | getExecutor(int numTasks, int maxThreads) get Executor if (numTasks <= maxThreads) { return Executors.newFixedThreadPool(numTasks); } else { return Executors.newFixedThreadPool(maxThreads); |
ScheduledExecutorService | getExecutorService() get Executor Service if ((es == null || es.isShutdown()) && !isExecutorShutdown()) { es = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() + ADDITIONAL_CORES); return es; |
ExecutorService | getExecutorService() get Executor Service if (service == null) { service = new ThreadPoolExecutor(1, MAX_CONCURRENT_REQUESTS, 10L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); return service; |
ExecutorService | getExecutorService() get Executor Service if (executorService == null) { executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2 + 2); return executorService; |
ExecutorService | getExecutorService(int maximumPoolSize, int corePoolSize, long keepAliveTime, final String name, RejectedExecutionHandler rejectionPolicy) Creates an ExecutorService object backed by a thread pool. final ThreadFactory factory = new ThreadFactory() { private final AtomicInteger counter = new AtomicInteger(0); public Thread newThread(Runnable r) { final Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); t.setName(name + '_' + counter.incrementAndGet()); return t; }; final ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize > 0 ? maximumPoolSize : Integer.MAX_VALUE, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), factory); if (rejectionPolicy != null) { executor.setRejectedExecutionHandler(rejectionPolicy); return executor; |
ExecutorService | getExecutorService(int poolSize) get Executor Service final ThreadFactory threadFactory = runnable -> { Thread thr = new Thread(runnable); thr.setDaemon(false); return thr; }; return Executors.newFixedThreadPool(poolSize, threadFactory); |
ExecutorService | getExecutorService(String usage) get Executor Service return executors.get(usage);
|