use of org.jboss.as.threads.TimeSpec in project eap-additional-testsuite by jboss-set.
the class ServletThreadPoolSelectionBoundedTestCase method testExecutor.
@Test
public void testExecutor() throws Exception {
int maxThreads = 10;
TimeSpec keepAliveSpec = new TimeSpec(SECONDS, 10);
long keepAliveTime = keepAliveSpec.getUnit().toNanos(keepAliveSpec.getDuration());
final JBossThreadPoolExecutorReuseIdleThreads jbossExecutor = new JBossThreadPoolExecutorReuseIdleThreads((int) (maxThreads / 2), maxThreads, keepAliveTime, TimeUnit.NANOSECONDS, new LinkedBlockingQueue<Runnable>(9990));
String result = null;
int rejected = 0;
ExecutorService executor = new ManagedJBossThreadPoolExecutorService(jbossExecutor);
try {
final List<Future<?>> results = new ArrayList<Future<?>>();
for (int i = 1; i < 100000; i++) {
try {
results.add(executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
HttpRequest.get(url.toExternalForm() + "/testNewThreadPool", 10, SECONDS);
return null;
}
}));
} catch (Exception e) {
// count the regjected tasks
rejected++;
}
}
for (Future<?> res : results) {
res.get();
}
Thread.sleep(10000);
result = HttpRequest.get(url.toExternalForm() + "/testNewThreadPool", 10, SECONDS);
assertEquals("100000", String.valueOf(Integer.parseInt(result) + rejected));
} finally {
executor.shutdown();
}
}
use of org.jboss.as.threads.TimeSpec in project eap-additional-testsuite by jboss-set.
the class ServletThreadPoolSelectionTestCase method testExecutor.
@Test
public void testExecutor() throws Exception {
int maxThreads = 10;
TimeSpec keepAliveSpec = new TimeSpec(SECONDS, 10);
long keepAliveTime = keepAliveSpec.getUnit().toNanos(keepAliveSpec.getDuration());
final JBossThreadPoolExecutorReuseIdleThreads jbossExecutor = new JBossThreadPoolExecutorReuseIdleThreads((int) (maxThreads / 2), maxThreads, keepAliveTime, TimeUnit.NANOSECONDS, new LinkedBlockingQueue<Runnable>());
ExecutorService executor = new ManagedJBossThreadPoolExecutorService(jbossExecutor);
try {
final List<Future<?>> results = new ArrayList<Future<?>>();
for (int i = 1; i < 100000; i++) {
results.add(executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
HttpRequest.get(url.toExternalForm() + "/testNewThreadPool", 10, SECONDS);
return null;
}
}));
}
for (Future<?> res : results) {
res.get();
}
String result = HttpRequest.get(url.toExternalForm() + "/testNewThreadPool", 10, SECONDS);
assertEquals("100000", result);
} finally {
executor.shutdown();
}
}
use of org.jboss.as.threads.TimeSpec in project camunda-bpm-platform by camunda.
the class JobExecutorAdd method performRuntimeThreadPool.
protected void performRuntimeThreadPool(OperationContext context, ModelNode model, String name, ServiceName jobExecutorThreadPoolServiceName, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException {
ServiceTarget serviceTarget = context.getServiceTarget();
ThreadFactoryService threadFactory = new ThreadFactoryService();
threadFactory.setThreadGroupName(THREAD_POOL_GRP_NAME + name);
ServiceName threadFactoryServiceName = ServiceNames.forThreadFactoryService(name);
ServiceBuilder<ThreadFactory> factoryBuilder = serviceTarget.addService(threadFactoryServiceName, threadFactory);
if (verificationHandler != null) {
factoryBuilder.addListener(verificationHandler);
}
if (newControllers != null) {
newControllers.add(factoryBuilder.install());
} else {
factoryBuilder.install();
}
final BoundedQueueThreadPoolService threadPoolService = new BoundedQueueThreadPoolService(SubsystemAttributeDefinitons.CORE_THREADS.resolveModelAttribute(context, model).asInt(), SubsystemAttributeDefinitons.MAX_THREADS.resolveModelAttribute(context, model).asInt(), SubsystemAttributeDefinitons.QUEUE_LENGTH.resolveModelAttribute(context, model).asInt(), false, new TimeSpec(TimeUnit.SECONDS, SubsystemAttributeDefinitons.KEEPALIVE_TIME.resolveModelAttribute(context, model).asInt()), SubsystemAttributeDefinitons.ALLOW_CORE_TIMEOUT.resolveModelAttribute(context, model).asBoolean());
ServiceBuilder<ManagedQueueExecutorService> builder = serviceTarget.addService(jobExecutorThreadPoolServiceName, threadPoolService).addDependency(threadFactoryServiceName, ThreadFactory.class, threadPoolService.getThreadFactoryInjector()).setInitialMode(ServiceController.Mode.ACTIVE);
if (verificationHandler != null) {
builder.addListener(verificationHandler);
}
if (newControllers != null) {
newControllers.add(builder.install());
} else {
builder.install();
}
}
Aggregations