/** * Creates an ExecutorService that uses a single worker thread operating off a bounded queue * with the specified capacity. Tasks are guaranteed to execute sequentially, and no more than * one task will be active at any given time. If the maximum queue capacity is reached, * subsequent tasks will be rejected. * * @param maximumQueueSize * the capacity of the queue. * @param threadPrefix * the name prefix for the thread created by this executor. * @param loggerIdentity * the class to use as logger name for logging uncaught exceptions from the threads. * @return a new ExecutorService with the specified configuration. */ public static ExecutorService newBoundedSingleThreadExecutor(int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity) { return new FastThreadPoolExecutor(1, maximumQueueSize, Long.MAX_VALUE, TimeUnit.SECONDS, 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", getQueue().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 #newBoundedFastThreadPool } 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 15 seconds. * @param maximumQueueSize * the capacity of the queue. * @param threadPrefix * the name prefix for threads created by this executor. * @param loggerIdentity * the class to use as logger name for logging uncaught exceptions from the threads. * @return a new ExecutorService with the specified configuration. */ public static ExecutorService newBlockingBoundedFastThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity) { FastThreadPoolExecutor executor = new FastThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity); executor.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerRunsPolicy()); return executor; }
this.maximumQueueSize = maximumQueueSize; setThreadFactory(ThreadFactoryProvider.builder().namePrefix(threadPrefix) .logger(LoggerFactory.getLogger(loggerIdentity)).build().get()); allowCoreThreadTimeOut(true); setRejectedExecutionHandler(CountingRejectedExecutionHandler.newAbortPolicy());
/** * Creates an ExecutorService similar to {@link #newBoundedFastThreadPool } 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 15 seconds. * @param maximumQueueSize * the capacity of the queue. * @param threadPrefix * the name prefix for threads created by this executor. * @param loggerIdentity * the class to use as logger name for logging uncaught exceptions from the threads. * @return a new ExecutorService with the specified configuration. */ public static ExecutorService newBlockingBoundedFastThreadPool(int maximumPoolSize, int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity) { FastThreadPoolExecutor executor = new FastThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity); executor.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerRunsPolicy()); return executor; }
this.maximumQueueSize = maximumQueueSize; setThreadFactory(ThreadFactoryProvider.builder().namePrefix(threadPrefix) .logger(LoggerFactory.getLogger(loggerIdentity)).build().get()); allowCoreThreadTimeOut(true); setRejectedExecutionHandler(CountingRejectedExecutionHandler.newAbortPolicy());
@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", getQueue().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(); } }
InMemoryDOMDataTreeShard(final DOMDataTreeIdentifier prefix, final Executor dataTreeChangeExecutor, final int maxDataChangeListenerQueueSize, final int submitQueueSize) { this.prefix = requireNonNull(prefix); final DataTreeConfiguration treeBaseConfig = treeTypeFor(prefix.getDatastoreType()); final DataTreeConfiguration treeConfig = new DataTreeConfiguration.Builder(treeBaseConfig.getTreeType()) .setMandatoryNodesValidation(treeBaseConfig.isMandatoryNodesValidationEnabled()) .setUniqueIndexes(treeBaseConfig.isUniqueIndexEnabled()) .setRootPath(prefix.getRootIdentifier()) .build(); this.dataTree = new InMemoryDataTreeFactory().create(treeConfig); this.shardChangePublisher = new InMemoryDOMDataTreeShardChangePublisher(dataTreeChangeExecutor, maxDataChangeListenerQueueSize, dataTree, prefix.getRootIdentifier(), childShards); final FastThreadPoolExecutor fte = new FastThreadPoolExecutor(1, submitQueueSize, "Shard[" + prefix + "]", InMemoryDOMDataTreeShard.class); fte.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerWaitsPolicy()); this.executor = MoreExecutors.listeningDecorator(fte); }
/** * Creates an ExecutorService that uses a single worker thread operating off a bounded queue * with the specified capacity. Tasks are guaranteed to execute sequentially, and no more than * one task will be active at any given time. If the maximum queue capacity is reached, * subsequent tasks will be rejected. * * @param maximumQueueSize * the capacity of the queue. * @param threadPrefix * the name prefix for the thread created by this executor. * @param loggerIdentity * the class to use as logger name for logging uncaught exceptions from the threads. * @return a new ExecutorService with the specified configuration. */ public static ExecutorService newBoundedSingleThreadExecutor(int maximumQueueSize, String threadPrefix, Class<?> loggerIdentity) { return new FastThreadPoolExecutor(1, maximumQueueSize, Long.MAX_VALUE, TimeUnit.SECONDS, threadPrefix, loggerIdentity); }
return new FastThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity);
return new FastThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix, loggerIdentity);