Search in sources :

Example 1 with DefaultNonBlockingThreadFactory

use of org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory in project wildfly by wildfly.

the class ClientThreadPoolServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    int maxThreads = this.definition.getMaxThreads().resolveModelAttribute(context, model).asInt();
    int minThreads = this.definition.getMinThreads().resolveModelAttribute(context, model).asInt();
    int queueLength = this.definition.getQueueLength().resolveModelAttribute(context, model).asInt();
    long keepAliveTime = this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong();
    boolean nonBlocking = this.definition.isNonBlocking();
    this.factory = new ExecutorFactory() {

        @Override
        public ExecutorService getExecutor(Properties property) {
            BlockingQueue<Runnable> queue = queueLength == 0 ? new SynchronousQueue<>() : new LinkedBlockingQueue<>(queueLength);
            ThreadFactory factory = new DefaultThreadFactory(new DaemonThreadFactory(DefaultAsyncExecutorFactory.THREAD_NAME));
            if (nonBlocking) {
                factory = new DefaultNonBlockingThreadFactory(factory);
            }
            RejectedExecutionHandler handler = nonBlocking ? NonBlockingRejectedExecutionHandler.getInstance() : BlockingRejectedExecutionHandler.getInstance();
            return new ThreadPoolExecutor(minThreads, maxThreads, keepAliveTime, TimeUnit.MILLISECONDS, queue, factory, handler);
        }
    };
    return this;
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DefaultNonBlockingThreadFactory(org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) NonBlockingRejectedExecutionHandler(org.infinispan.commons.util.concurrent.NonBlockingRejectedExecutionHandler) BlockingRejectedExecutionHandler(org.infinispan.commons.util.concurrent.BlockingRejectedExecutionHandler) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) Properties(java.util.Properties) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DefaultThreadFactory(org.jboss.as.clustering.context.DefaultThreadFactory) ExecutorFactory(org.infinispan.commons.executors.ExecutorFactory) DefaultAsyncExecutorFactory(org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory) SynchronousQueue(java.util.concurrent.SynchronousQueue) ExecutorService(java.util.concurrent.ExecutorService) DefaultNonBlockingThreadFactory(org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

Properties (java.util.Properties)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 DefaultAsyncExecutorFactory (org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory)1 ExecutorFactory (org.infinispan.commons.executors.ExecutorFactory)1 BlockingRejectedExecutionHandler (org.infinispan.commons.util.concurrent.BlockingRejectedExecutionHandler)1 NonBlockingRejectedExecutionHandler (org.infinispan.commons.util.concurrent.NonBlockingRejectedExecutionHandler)1 DefaultThreadFactory (org.jboss.as.clustering.context.DefaultThreadFactory)1 DefaultNonBlockingThreadFactory (org.wildfly.clustering.infinispan.spi.DefaultNonBlockingThreadFactory)1