/** * Shutdown the thread pool, give a grace period of 1 second before forcibly * shutting down all worker threads. */ @Override public void deconstruct() { boolean terminated; super.deconstruct(); threadpool.shutdown(); try { terminated = threadpool.awaitTermination(1, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } if (!terminated) { threadpool.shutdownNow(); } }
public ThreadPoolProvider(ThreadpoolConfig threadpoolConfig, Metric metric, ProcessTerminator processTerminator) { WorkerCompletionTimingThreadPoolExecutor executor = new WorkerCompletionTimingThreadPoolExecutor(threadpoolConfig.maxthreads(), threadpoolConfig.maxthreads(), 0L, TimeUnit.SECONDS, new SynchronousQueue<>(false), ThreadFactoryFactory.getThreadFactory("threadpool")); // Prestart needed, if not all threads will be created by the fist N tasks and hence they might also // get the dreaded thread locals initialized even if they will never run. // That counters what we we want to achieve with the Q that will prefer thread locality. executor.prestartAllCoreThreads(); threadpool = new ExecutorServiceWrapper(executor, metric, processTerminator, threadpoolConfig.maxThreadExecutionTimeSeconds() * 1000L); }