Search in sources :

Example 1 with ThreadPoolExecutorFactory

use of org.infinispan.commons.executors.ThreadPoolExecutorFactory in project wildfly by wildfly.

the class ScheduledThreadPoolBuilder method configure.

@Override
public Builder<ThreadPoolConfiguration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    int maxThreads = this.definition.getMaxThreads().resolveModelAttribute(context, model).asInt();
    long keepAliveTime = this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong();
    ThreadPoolExecutorFactory<?> factory = new ThreadPoolExecutorFactory<ScheduledExecutorService>() {

        @Override
        public ScheduledExecutorService createExecutor(ThreadFactory factory) {
            // Use fixed size, based on maxThreads
            ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(maxThreads, new ClassLoaderThreadFactory(factory, ClassLoaderThreadFactory.class.getClassLoader()));
            executor.setKeepAliveTime(keepAliveTime, TimeUnit.MILLISECONDS);
            executor.setRemoveOnCancelPolicy(true);
            executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
            return executor;
        }

        @Override
        public void validate() {
        // Do nothing
        }
    };
    this.builder.threadPoolFactory(factory);
    return this;
}
Also used : ClassLoaderThreadFactory(org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutorFactory(org.infinispan.commons.executors.ThreadPoolExecutorFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ClassLoaderThreadFactory(org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutorFactory (org.infinispan.commons.executors.ThreadPoolExecutorFactory)1 ClassLoaderThreadFactory (org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory)1