/** * 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; }
/** * 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; }
setRejectedExecutionHandler(CountingRejectedExecutionHandler.newAbortPolicy());
setRejectedExecutionHandler(CountingRejectedExecutionHandler.newAbortPolicy());
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); }