use of org.jboss.as.threads.ManagedJBossThreadPoolExecutorService 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.ManagedJBossThreadPoolExecutorService 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();
}
}
Aggregations