Search in sources :

Example 1 with JBossThreadPoolExecutorReuseIdleThreads

use of org.jboss.threads.JBossThreadPoolExecutorReuseIdleThreads 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();
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) TimeSpec(org.jboss.as.threads.TimeSpec) ManagedJBossThreadPoolExecutorService(org.jboss.as.threads.ManagedJBossThreadPoolExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) JBossThreadPoolExecutorReuseIdleThreads(org.jboss.threads.JBossThreadPoolExecutorReuseIdleThreads) ManagedJBossThreadPoolExecutorService(org.jboss.as.threads.ManagedJBossThreadPoolExecutorService) Test(org.junit.Test)

Example 2 with JBossThreadPoolExecutorReuseIdleThreads

use of org.jboss.threads.JBossThreadPoolExecutorReuseIdleThreads 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();
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) TimeSpec(org.jboss.as.threads.TimeSpec) ManagedJBossThreadPoolExecutorService(org.jboss.as.threads.ManagedJBossThreadPoolExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) JBossThreadPoolExecutorReuseIdleThreads(org.jboss.threads.JBossThreadPoolExecutorReuseIdleThreads) ManagedJBossThreadPoolExecutorService(org.jboss.as.threads.ManagedJBossThreadPoolExecutorService) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 ManagedJBossThreadPoolExecutorService (org.jboss.as.threads.ManagedJBossThreadPoolExecutorService)2 TimeSpec (org.jboss.as.threads.TimeSpec)2 JBossThreadPoolExecutorReuseIdleThreads (org.jboss.threads.JBossThreadPoolExecutorReuseIdleThreads)2 Test (org.junit.Test)2