Search in sources :

Example 1 with TimeSpec

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();
    }
}
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 TimeSpec

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();
    }
}
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 3 with TimeSpec

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();
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BoundedQueueThreadPoolService(org.jboss.as.threads.BoundedQueueThreadPoolService) ManagedQueueExecutorService(org.jboss.as.threads.ManagedQueueExecutorService) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) ThreadFactoryService(org.jboss.as.threads.ThreadFactoryService) TimeSpec(org.jboss.as.threads.TimeSpec)

Aggregations

TimeSpec (org.jboss.as.threads.TimeSpec)3 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 JBossThreadPoolExecutorReuseIdleThreads (org.jboss.threads.JBossThreadPoolExecutorReuseIdleThreads)2 Test (org.junit.Test)2 ThreadFactory (java.util.concurrent.ThreadFactory)1 BoundedQueueThreadPoolService (org.jboss.as.threads.BoundedQueueThreadPoolService)1 ManagedQueueExecutorService (org.jboss.as.threads.ManagedQueueExecutorService)1 ThreadFactoryService (org.jboss.as.threads.ThreadFactoryService)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1