Search in sources :

Example 1 with NameableThreadFactory

use of com.datatorrent.common.util.NameableThreadFactory in project apex-core by apache.

the class DefaultApexPluginDispatcher method serviceInit.

@Override
protected void serviceInit(Configuration conf) throws Exception {
    super.serviceInit(conf);
    LOG.debug("Creating plugin dispatch queue with size {}", qsize);
    blockingQueue = new ArrayBlockingQueue<>(qsize);
    RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler() {

        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
            try {
                blockingQueue.remove();
                executor.submit(r);
            } catch (NoSuchElementException ex) {
            // Ignore no-such element as queue may finish, while this handler is called.
            }
        }
    };
    executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, blockingQueue, new NameableThreadFactory("PluginExecutorThread"), rejectionHandler);
}
Also used : RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) NameableThreadFactory(com.datatorrent.common.util.NameableThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NameableThreadFactory (com.datatorrent.common.util.NameableThreadFactory)1 NoSuchElementException (java.util.NoSuchElementException)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1