@Override public ServiceConfigurator 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, WildFlySecurityManager.doUnchecked(GET_CLASS_LOADER_ACTION))); 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; }
@Override public ThreadPoolConfiguration get() { return this.builder.create(); } }
builder.transport().transportThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.TRANSPORT).get()); builder.transport().remoteCommandThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.REMOTE_COMMAND).get()); builder.asyncThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.ASYNC_OPERATIONS).get()); builder.expirationThreadPool().read(this.schedulers.get(ScheduledThreadPoolResourceDefinition.EXPIRATION).get()); builder.listenerThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.LISTENER).get()); builder.stateTransferThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.STATE_TRANSFER).get()); builder.persistenceThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.PERSISTENCE).get());
case ASYNC_LISTENER_EXECUTOR: { ThreadPoolExecutorFactory executorFactory = createBlockingThreadPoolExecutorFactory(parseExecutor(reader)); holder.getGlobalConfigurationBuilder().listenerThreadPool().threadFactory(threadFactory).threadPoolFactory(executorFactory); break; holder.getGlobalConfigurationBuilder().persistenceThreadPool().threadFactory(threadFactory).threadPoolFactory(executorFactory); break; holder.getGlobalConfigurationBuilder().transport().transportThreadPool().threadFactory(threadFactory).threadPoolFactory(executorFactory); break; holder.getGlobalConfigurationBuilder().transport().remoteCommandThreadPool().threadFactory(threadFactory).threadPoolFactory(executorFactory); break; holder.getGlobalConfigurationBuilder().expirationThreadPool().threadFactory(threadFactory).threadPoolFactory(executorFactory); break;
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { GlobalConfigurationBuilder globalCfg = new GlobalConfigurationBuilder(); globalCfg.expirationThreadPool().threadFactory(new DefaultThreadFactory(null, 1, EXPIRATION_THREAD_NAME_PREFIX, null, null)); return TestCacheManagerFactory.createCacheManager(globalCfg, new ConfigurationBuilder()); }
@Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { ThreadPoolExecutorFactory<?> factory = new BlockingThreadPoolExecutorFactory( this.definition.getMaxThreads().resolveModelAttribute(context, model).asInt(), this.definition.getMinThreads().resolveModelAttribute(context, model).asInt(), this.definition.getQueueLength().resolveModelAttribute(context, model).asInt(), this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong() ) { @Override public ExecutorService createExecutor(ThreadFactory factory) { return super.createExecutor(new ClassLoaderThreadFactory(factory, WildFlySecurityManager.doUnchecked(GET_CLASS_LOADER_ACTION))); } }; this.builder.threadPoolFactory(factory); return this; }
@Override public ThreadPoolConfiguration get() { return this.builder.create(); } }
builder.transport().transportThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.TRANSPORT).get()); builder.transport().remoteCommandThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.REMOTE_COMMAND).get()); builder.asyncThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.ASYNC_OPERATIONS).get()); builder.expirationThreadPool().read(this.schedulers.get(ScheduledThreadPoolResourceDefinition.EXPIRATION).get()); builder.listenerThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.LISTENER).get()); builder.stateTransferThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.STATE_TRANSFER).get()); builder.persistenceThreadPool().read(this.pools.get(ThreadPoolResourceDefinition.PERSISTENCE).get());
public static void minimizeThreads(GlobalConfigurationBuilder builder) { BlockingThreadPoolExecutorFactory executorFactoryNoQueue = new BlockingThreadPoolExecutorFactory(NAMED_EXECUTORS_THREADS_NO_QUEUE, 0, 0, NAMED_EXECUTORS_KEEP_ALIVE); BlockingThreadPoolExecutorFactory executorFactoryWithQueue = new BlockingThreadPoolExecutorFactory(NAMED_EXECUTORS_THREADS_WITH_QUEUE, NAMED_EXECUTORS_THREADS_WITH_QUEUE, NAMED_EXECUTORS_QUEUE_SIZE, NAMED_EXECUTORS_KEEP_ALIVE); builder.transport().remoteCommandThreadPool().threadPoolFactory(executorFactoryNoQueue); builder.stateTransferThreadPool().threadPoolFactory(executorFactoryNoQueue); builder.asyncThreadPool().threadPoolFactory(executorFactoryWithQueue); builder.listenerThreadPool().threadPoolFactory(executorFactoryWithQueue); builder.transport().transportThreadPool().threadPoolFactory(executorFactoryWithQueue); // TODO Scheduled thread pools don't have a threads limit // Timeout thread pool is not configurable at all }
@Override public ThreadPoolConfiguration getValue() throws IllegalStateException, IllegalArgumentException { return this.builder.create(); } }
transportBuilder.transportThreadPool().read(this.transportThreadPool.getValue()); transportBuilder.remoteCommandThreadPool().read(this.remoteCommandThreadPool.getValue()); builder.asyncThreadPool().read(this.asyncOperationsThreadPool.getValue()); builder.expirationThreadPool().read(this.expirationThreadPool.getValue()); builder.listenerThreadPool().read(this.listenerThreadPool.getValue()); builder.stateTransferThreadPool().read(this.stateTransferThreadPool.getValue()); builder.persistenceThreadPool().read(this.persistenceThreadPool.getValue()); builder.replicationQueueThreadPool().read(this.replicationQueueThreadPool.getValue());
@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) { ScheduledThreadPoolExecutor scheduledExecutor = new ScheduledThreadPoolExecutor(0); scheduledExecutor.setCorePoolSize(maxThreads); scheduledExecutor.setKeepAliveTime(keepAliveTime, TimeUnit.MILLISECONDS); return scheduledExecutor; } @Override public void validate() { } }; this.builder.threadPoolFactory(factory); return this; }
@Override public ThreadPoolConfiguration getValue() throws IllegalStateException, IllegalArgumentException { return this.builder.create(); }
@Override public ServiceConfigurator 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, WildFlySecurityManager.doUnchecked(GET_CLASS_LOADER_ACTION))); 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; }
@Override public ThreadPoolConfiguration get() { return this.builder.create(); } }
private GlobalConfigurationBuilder getGlobalConfigurationBuilder() { GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder(); BlockingThreadPoolExecutorFactory threadPoolFactory = new BlockingThreadPoolExecutorFactory(1, 1, 0, Thread.NORM_PRIORITY); globalBuilder.transport().remoteCommandThreadPool().threadPoolFactory(threadPoolFactory); return globalBuilder; }
@Override public ThreadPoolConfiguration get() { return this.builder.create(); } }
protected EmbeddedCacheManager addClusterEnabledCacheManager(TransportFlags flags) { GlobalConfigurationBuilder gcb = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Amend first so we can increase the transport thread pool TestCacheManagerFactory.amendGlobalConfiguration(gcb, flags); // we need to increase the transport and remote thread pools to default values BlockingThreadPoolExecutorFactory executorFactory = new BlockingThreadPoolExecutorFactory( 25, 25, 10000, 30000); gcb.transport().transportThreadPool().threadPoolFactory(executorFactory); gcb.transport().remoteCommandThreadPool().threadPoolFactory(executorFactory); EmbeddedCacheManager cm = TestCacheManagerFactory.newDefaultCacheManager(true, gcb, new ConfigurationBuilder(), false); cacheManagers.add(cm); return cm; }
protected EmbeddedCacheManager addClusterEnabledCacheManager(TransportFlags flags) { GlobalConfigurationBuilder gcb = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Amend first so we can increase the transport thread pool TestCacheManagerFactory.amendGlobalConfiguration(gcb, flags); // we need to increase the transport and remote thread pools to default values BlockingThreadPoolExecutorFactory executorFactory = new BlockingThreadPoolExecutorFactory( 25, 25, 10000, 30000); gcb.transport().transportThreadPool().threadPoolFactory(executorFactory); gcb.transport().remoteCommandThreadPool().threadPoolFactory(executorFactory); EmbeddedCacheManager cm = TestCacheManagerFactory.newDefaultCacheManager(true, gcb, new ConfigurationBuilder(), false); cacheManagers.add(cm); return cm; }
protected EmbeddedCacheManager addClusterEnabledCacheManager(TransportFlags flags) { GlobalConfigurationBuilder gcb = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Amend first so we can increase the transport thread pool TestCacheManagerFactory.amendGlobalConfiguration(gcb, flags); // we need to increase the transport and remote thread pools to default values BlockingThreadPoolExecutorFactory executorFactory = new BlockingThreadPoolExecutorFactory( 25, 25, 10000, 30000); gcb.transport().transportThreadPool().threadPoolFactory(executorFactory); gcb.transport().remoteCommandThreadPool().threadPoolFactory(executorFactory); EmbeddedCacheManager cm = TestCacheManagerFactory.newDefaultCacheManager(true, gcb, new ConfigurationBuilder(), false); cacheManagers.add(cm); return cm; }