@Override public ExecutorService createExecutor(ThreadFactory factory) { return super.createExecutor(new ClassLoaderThreadFactory(factory, WildFlySecurityManager.doUnchecked(GET_CLASS_LOADER_ACTION))); } };
public static BlockingThreadPoolExecutorFactory create(int maxThreads, int queueSize) { int coreThreads = queueSize == 0 ? 1 : maxThreads; return new BlockingThreadPoolExecutorFactory( maxThreads, coreThreads, queueSize, 60000); }
private ThreadPoolExecutorFactory createCachedThreadPoolExecutorFactory(TypedProperties tp) { return CachedThreadPoolExecutorFactory.create(); }
assertEquals(5, threadFactory.initialPriority()); threadPool = getGlobalConfiguration(holder).asyncThreadPool().threadPoolFactory(); assertEquals(5, threadPool.coreThreads()); assertEquals(5, threadPool.maxThreads()); assertEquals(0, threadPool.queueLength()); assertEquals(0, threadPool.keepAlive()); assertEquals(5, threadFactory.initialPriority()); threadPool = getGlobalConfiguration(holder).stateTransferThreadPool().threadPoolFactory(); assertEquals(1, threadPool.coreThreads()); assertEquals(60, threadPool.maxThreads()); assertEquals(0, threadPool.queueLength()); assertEquals(0, threadPool.keepAlive());
private ThreadPoolExecutorFactory createScheduledThreadPoolExecutorFactory(TypedProperties tp) { return ScheduledThreadPoolExecutorFactory.create(); }
public void testGlobalConfig() throws Exception { ConfigurationBuilderHolder holder = parse(); GlobalConfiguration gc = holder.getGlobalConfigurationBuilder().build(); BlockingThreadPoolExecutorFactory listenerThreadPool = gc.listenerThreadPool().threadPoolFactory(); assertEquals(2, listenerThreadPool.maxThreads()); BlockingThreadPoolExecutorFactory persistenceThreadPool = gc.persistenceThreadPool().threadPoolFactory(); assertEquals(4, persistenceThreadPool.maxThreads()); Properties transportProps = gc.transport().properties(); assertEquals("jgroups-tcp.xml", transportProps.get("configurationFile")); Configuration configuration = holder.getDefaultConfigurationBuilder().build(); assertEquals(IsolationLevel.READ_COMMITTED, configuration.locking().isolationLevel()); } }
private ThreadPoolExecutorFactory createBlockingThreadPoolExecutorFactory(TypedProperties tp) { int maxThreads = tp.getIntProperty("maxThreads", 1); int queueSize = tp.getIntProperty("queueSize", 100000); int coreThreads = queueSize == 0 ? 1 : tp.getIntProperty("coreThreads", maxThreads); long keepAliveTime = tp.getLongProperty("keepAliveTime", 60000); return new BlockingThreadPoolExecutorFactory(maxThreads, coreThreads, queueSize, keepAliveTime); }
assertEquals(5, listenerThreadPool.maxThreads()); assertEquals(10000, listenerThreadPool.queueLength()); DefaultThreadFactory listenerThreadFactory = gc.listenerThreadPool().threadFactory(); assertEquals(6, persistenceThreadPool.maxThreads()); assertEquals(10001, persistenceThreadPool.queueLength()); DefaultThreadFactory persistenceThreadFactory = gc.persistenceThreadPool().threadFactory(); assertEquals(5, asyncThreadPool.coreThreads()); assertEquals(5, asyncThreadPool.maxThreads()); assertEquals(10000, asyncThreadPool.queueLength()); assertEquals(0, asyncThreadPool.keepAlive()); DefaultThreadFactory asyncThreadFactory = gc.asyncThreadPool().threadFactory(); assertEquals("AsyncOperationsThread", asyncThreadFactory.threadNamePattern()); assertEquals(25, transportThreadPool.maxThreads()); assertEquals(10000, transportThreadPool.queueLength()); assertEquals(0, transportThreadPool.keepAlive()); assertEquals(30, remoteCommandThreadPool.maxThreads()); assertEquals(2, remoteCommandThreadPool.coreThreads()); assertEquals(10000, remoteCommandThreadPool.queueLength()); assertEquals(10000, remoteCommandThreadPool.keepAlive()); assertEquals(20, stateTransferThreadPool.maxThreads()); assertEquals(2, remoteCommandThreadPool.coreThreads()); assertEquals(5, stateTransferThreadPool.queueLength());
public void amendConfiguration(ConfigurationBuilderHolder holder) { TransportConfigurationBuilder transport = holder.getGlobalConfigurationBuilder().transport(); transport.nodeName(TestResourceTracker.getNextNodeName()); transport.clusterName(TestResourceTracker.getCurrentTestName()); // minimize number of threads using unlimited cached thread pool transport.remoteCommandThreadPool().threadPoolFactory(CachedThreadPoolExecutorFactory.create()); transport.transportThreadPool().threadPoolFactory(CachedThreadPoolExecutorFactory.create()); for (Map.Entry<String, ConfigurationBuilder> cfg : holder.getNamedConfigurationBuilders().entrySet()) { amendCacheConfiguration(cfg.getKey(), cfg.getValue()); } // disable simple cache for testing as we need to insert interceptors if (!pendingPutsSimple) { holder.getNamedConfigurationBuilders().get(DEF_PENDING_PUTS_RESOURCE).simpleCache(false); } }
@Override public ExecutorService createExecutor(ThreadFactory factory) { return super.createExecutor(new ClassLoaderThreadFactory(factory, WildFlySecurityManager.doUnchecked(GET_CLASS_LOADER_ACTION))); } };
private GlobalConfigurationBuilder getGlobalConfigurationBuilder() { GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder(); BlockingThreadPoolExecutorFactory threadPoolFactory = new BlockingThreadPoolExecutorFactory(1, 1, 0, Thread.NORM_PRIORITY); globalBuilder.transport().remoteCommandThreadPool().threadPoolFactory(threadPoolFactory); return globalBuilder; }
assertEquals(5, threadFactory.initialPriority()); threadPool = getGlobalConfiguration(holder).listenerThreadPool().threadPoolFactory(); assertEquals(1, threadPool.coreThreads()); assertEquals(1, threadPool.maxThreads()); assertEquals(0, threadPool.queueLength()); assertEquals(0, threadPool.keepAlive()); assertEquals(5, threadFactory.initialPriority()); threadPool = getGlobalConfiguration(holder).transport().transportThreadPool().threadPoolFactory(); assertEquals(5, threadPool.coreThreads()); assertEquals(10, threadPool.maxThreads()); assertEquals(100, threadPool.queueLength()); assertEquals(10000, threadPool.keepAlive());
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 Builder<ThreadPoolConfiguration> 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() ); this.builder.threadPoolFactory(factory); return this; }
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; }
gcb.transport().defaultTransport().nodeName(nodeName) .addProperty(JGroupsTransport.CONFIGURATION_STRING, configurator.getProtocolStackString()); BlockingThreadPoolExecutorFactory transportExecutorFactory = new BlockingThreadPoolExecutorFactory( TRANSPORT_MAX_THREADS, TRANSPORT_MAX_THREADS, TRANSPORT_QUEUE_SIZE, 60000); gcb.transport().transportThreadPool().threadPoolFactory(transportExecutorFactory); BlockingThreadPoolExecutorFactory remoteExecutorFactory = new BlockingThreadPoolExecutorFactory( REMOTE_MAX_THREADS, REMOTE_MAX_THREADS, REMOTE_QUEUE_SIZE, 60000); gcb.transport().remoteCommandThreadPool().threadPoolFactory(remoteExecutorFactory); BlockingThreadPoolExecutorFactory stateTransferExecutorFactory = new BlockingThreadPoolExecutorFactory( STATE_TRANSFER_MAX_THREADS, STATE_TRANSFER_MAX_THREADS, STATE_TRANSFER_QUEUE_SIZE, 60000); gcb.transport().stateTransferThreadPool().threadPoolFactory(stateTransferExecutorFactory);
@Override public Object call() throws Exception { GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); gcb.transport().defaultTransport().nodeName(nodeName); // gcb.transport().machineId(machineId); BlockingThreadPoolExecutorFactory remoteExecutorFactory = new BlockingThreadPoolExecutorFactory( 10, 1, 0, 60000); gcb.transport().remoteCommandThreadPool().threadPoolFactory(remoteExecutorFactory); BlockingThreadPoolExecutorFactory stateTransferExecutorFactory = new BlockingThreadPoolExecutorFactory( 4, 1, 0, 60000); gcb.transport().stateTransferThreadPool().threadPoolFactory(stateTransferExecutorFactory); EmbeddedCacheManager cm = new DefaultCacheManager(gcb.build()); try { for (int j = 0; j < NUM_CACHES/2; j++) { cm.defineConfiguration("repl-cache-" + j, replConfig); cm.defineConfiguration("dist-cache-" + j, distConfig); } for (int j = 0; j < NUM_CACHES/2; j++) { Cache<Object, Object> replCache = cm.getCache("repl-cache-" + j); replCache.put(cm.getAddress(), "bla"); Cache<Object, Object> distCache = cm.getCache("dist-cache-" + j); distCache.put(cm.getAddress(), "bla"); } } finally { registerCacheManager(cm); } log.infof("Started cache manager %s", cm.getAddress()); return null; } });
@Override protected void createCacheManagers() throws Throwable { Configuration distConfig = getDefaultClusteredCacheConfig(cacheMode, false).build(); for (int i = 0; i < NUM_NODES; i++) { GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); gcb.transport().defaultTransport().nodeName(TestResourceTracker.getNameForIndex(i)); BlockingThreadPoolExecutorFactory remoteExecutorFactory = new BlockingThreadPoolExecutorFactory( 10, 1, 0, 60000); gcb.transport().remoteCommandThreadPool().threadPoolFactory(remoteExecutorFactory); EmbeddedCacheManager cm = new DefaultCacheManager(gcb.build()); registerCacheManager(cm); cm.defineConfiguration(CACHE_NAME, distConfig); log.infof("Started cache manager %s", cm.getAddress()); } waitForClusterToForm(CACHE_NAME); }