return new CachedThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity);
@Override public final String toString() { return addToStringAttributes(MoreObjects.toStringHelper(this) .add("Thread Prefix", threadPrefix) .add("Current Thread Pool Size", getPoolSize()) .add("Largest Thread Pool Size", getLargestPoolSize()) .add("Max Thread Pool Size", getMaximumPoolSize()) .add("Current Queue Size", executorQueue.getBackingQueue().size()) .add("Largest Queue Size", getLargestQueueSize()) .add("Max Queue Size", maximumQueueSize) .add("Active Thread Count", getActiveCount()) .add("Completed Task Count", getCompletedTaskCount()) .add("Total Task Count", getTaskCount())).toString(); }
/** * Creates an ExecutorService similar to {@link #newBoundedCachedThreadPool } except that it * handles rejected tasks by running them in the same thread as the caller. Therefore if the * queue is full, the caller submitting the task will be blocked until the task completes. In * this manner, tasks are never rejected. * * @param maximumPoolSize * the maximum number of threads to allow in the pool. Threads will terminate after * being idle for 60 seconds. * @param maximumQueueSize * the capacity of the queue. * @param threadPrefix * the name prefix for threads created by this executor. * @return a new ExecutorService with the specified configuration. */ public static ExecutorService newBlockingBoundedCachedThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity) { CachedThreadPoolExecutor executor = new CachedThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity); executor.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerRunsPolicy()); return executor; }
/** * Creates an ExecutorService similar to {@link #newBoundedCachedThreadPool } except that it * handles rejected tasks by running them in the same thread as the caller. Therefore if the * queue is full, the caller submitting the task will be blocked until the task completes. In * this manner, tasks are never rejected. * * @param maximumPoolSize * the maximum number of threads to allow in the pool. Threads will terminate after * being idle for 60 seconds. * @param maximumQueueSize * the capacity of the queue. * @param threadPrefix * the name prefix for threads created by this executor. * @return a new ExecutorService with the specified configuration. */ public static ExecutorService newBlockingBoundedCachedThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity) { CachedThreadPoolExecutor executor = new CachedThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity); executor.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerRunsPolicy()); return executor; }
@Override public final String toString() { return addToStringAttributes(MoreObjects.toStringHelper(this) .add("Thread Prefix", threadPrefix) .add("Current Thread Pool Size", getPoolSize()) .add("Largest Thread Pool Size", getLargestPoolSize()) .add("Max Thread Pool Size", getMaximumPoolSize()) .add("Current Queue Size", executorQueue.getBackingQueue().size()) .add("Largest Queue Size", getLargestQueueSize()) .add("Max Queue Size", maximumQueueSize) .add("Active Thread Count", getActiveCount()) .add("Completed Task Count", getCompletedTaskCount()) .add("Total Task Count", getTaskCount())).toString(); }
return new CachedThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity);