use of java.util.concurrent.ThreadFactory in project wildfly by wildfly.
the class WeldExecutorServices method start.
@Override
public void start(StartContext context) throws StartException {
final ThreadGroup threadGroup = new ThreadGroup("Weld ThreadGroup");
final ThreadFactory factory = new JBossThreadFactory(threadGroup, Boolean.FALSE, null, THREAD_NAME_PATTERN, null, null);
// set TCCL to null for new threads to make sure no deployment classloader leaks through this executor's TCCL
// Weld does not mind having null TCCL in this executor
this.executor = Executors.newFixedThreadPool(bound, runnable -> {
Thread thread = factory.newThread(runnable);
if (WildFlySecurityManager.isChecking()) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
thread.setContextClassLoader(null);
return null;
}
});
} else {
thread.setContextClassLoader(null);
}
return thread;
});
}
use of java.util.concurrent.ThreadFactory in project wildfly by wildfly.
the class KeyAffinityServiceFactoryBuilder method build.
@Override
public ServiceBuilder<KeyAffinityServiceFactory> build(ServiceTarget target) {
int bufferSize = this.bufferSize;
Function<ExecutorService, KeyAffinityServiceFactory> mapper = executor -> new KeyAffinityServiceFactory() {
@Override
public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) {
CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode();
return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator);
}
};
Supplier<ExecutorService> supplier = () -> {
ThreadGroup threadGroup = new ThreadGroup("KeyAffinityService ThreadGroup");
String namePattern = "KeyAffinityService Thread Pool -- %t";
PrivilegedAction<ThreadFactory> action = () -> new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
return Executors.newCachedThreadPool(doPrivileged(action));
};
Service<KeyAffinityServiceFactory> service = new SuppliedValueService<>(mapper, supplier, ExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.getServiceName(), service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of java.util.concurrent.ThreadFactory 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;
}
use of java.util.concurrent.ThreadFactory in project voldemort by voldemort.
the class MetadataStressTest method main.
public static void main(String[] args) throws Exception {
if (args.length < 3) {
System.err.println("java voldemort.performance.MetadataStressTest url iterations threads selectors");
System.exit(-1);
}
String url = args[0];
final int count = Integer.parseInt(args[1]);
int numThreads = Integer.parseInt(args[2]);
int numSelectors = args.length > 3 ? Integer.parseInt(args[3]) : 8;
int timeoutSecs = args.length > 4 ? Integer.parseInt(args[4]) : 10;
ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName("stress-test");
return thread;
}
});
try {
final SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url).setEnableLazy(false).setConnectionTimeout(timeoutSecs, TimeUnit.SECONDS).setSocketTimeout(timeoutSecs, TimeUnit.SECONDS).setMaxThreads(numThreads).setSelectors(numSelectors));
for (int i = 0; i < numThreads; i++) {
executor.submit(new Runnable() {
public void run() {
for (int j = 0; j < count; j++) {
try {
String clusterXml = factory.bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
new ClusterMapper().readCluster(new StringReader(clusterXml));
String storesXml = factory.bootstrapMetadataWithRetries(MetadataStore.STORES_KEY);
new StoreDefinitionsMapper().readStoreList(new StringReader(storesXml));
if (logger.isTraceEnabled())
logger.trace("ok " + j);
} catch (MappingException me) {
logger.fatal(me, me);
System.exit(-1);
} catch (Exception e) {
logger.error(e, e);
}
}
}
});
}
} finally {
executor.shutdown();
}
}
use of java.util.concurrent.ThreadFactory in project gerrit by GerritCodeReview.
the class StreamCommandExecutorProvider method get.
@Override
public WorkQueue.Executor get() {
final WorkQueue.Executor executor;
executor = queues.createQueue(poolSize, "SSH-Stream-Worker");
final ThreadFactory parent = executor.getThreadFactory();
executor.setThreadFactory(new ThreadFactory() {
@Override
public Thread newThread(final Runnable task) {
final Thread t = parent.newThread(task);
t.setPriority(Thread.MIN_PRIORITY);
return t;
}
});
return executor;
}
Aggregations