Java Utililty Methods Thread Executor Create

List of utility methods to do Thread Executor Create

Description

The list of methods to do Thread Executor Create are organized into topic(s).

Method

ScheduledExecutorServicecreateStatisticsExecutor()
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;
...
ThreadFactorycreateThreadFactory(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++;
...
ExecutorServicegetExecutor()
Gets an existing cached thread pool or creates new one if none exists
if (executor == null) {
    executor = Executors.newCachedThreadPool();
return executor;
ExecutorServicegetExecutor(int numTasks, int maxThreads)
get Executor
if (numTasks <= maxThreads) {
    return Executors.newFixedThreadPool(numTasks);
} else {
    return Executors.newFixedThreadPool(maxThreads);
ScheduledExecutorServicegetExecutorService()
get Executor Service
if ((es == null || es.isShutdown()) && !isExecutorShutdown()) {
    es = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() + ADDITIONAL_CORES);
return es;
ExecutorServicegetExecutorService()
get Executor Service
if (service == null) {
    service = new ThreadPoolExecutor(1, MAX_CONCURRENT_REQUESTS, 10L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());
return service;
ExecutorServicegetExecutorService()
get Executor Service
if (executorService == null) {
    executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2 + 2);
return executorService;
ExecutorServicegetExecutorService(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;
ExecutorServicegetExecutorService(int poolSize)
get Executor Service
final ThreadFactory threadFactory = runnable -> {
    Thread thr = new Thread(runnable);
    thr.setDaemon(false);
    return thr;
};
return Executors.newFixedThreadPool(poolSize, threadFactory);
ExecutorServicegetExecutorService(String usage)
get Executor Service
return executors.get(usage);