Search in sources :

Example 1 with JmxManagedThreadPool

use of org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool in project camunda-bpm-platform by camunda.

the class StartManagedThreadPoolStep method performOperationStep.

public void performOperationStep(DeploymentOperation operationContext) {
    final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
    JobExecutorXml jobExecutorXml = getJobExecutorXml(operationContext);
    int queueSize = getQueueSize(jobExecutorXml);
    int corePoolSize = getCorePoolSize(jobExecutorXml);
    int maxPoolSize = getMaxPoolSize(jobExecutorXml);
    long keepAliveTime = getKeepAliveTime(jobExecutorXml);
    // initialize Queue & Executor services
    BlockingQueue<Runnable> threadPoolQueue = new ArrayBlockingQueue<Runnable>(queueSize);
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, threadPoolQueue);
    threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
    // construct the service for the thread pool
    JmxManagedThreadPool managedThreadPool = new JmxManagedThreadPool(threadPoolQueue, threadPoolExecutor);
    // install the service into the container
    serviceContainer.startService(ServiceTypes.BPM_PLATFORM, RuntimeContainerDelegateImpl.SERVICE_NAME_EXECUTOR, managedThreadPool);
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) PlatformServiceContainer(org.camunda.bpm.container.impl.spi.PlatformServiceContainer) JmxManagedThreadPool(org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool) JobExecutorXml(org.camunda.bpm.container.impl.metadata.spi.JobExecutorXml) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with JmxManagedThreadPool

use of org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool in project camunda-bpm-platform by camunda.

the class StartManagedThreadPoolStepTest method performOperationStepWithPropertiesInXml.

@Test
public void performOperationStepWithPropertiesInXml() {
    Map<String, String> properties = new HashMap<String, String>();
    String queueSize = "5";
    String corePoolSize = "12";
    String maxPoolSize = "20";
    String keepAliveTime = "100";
    properties.put(JobExecutorXml.CORE_POOL_SIZE, corePoolSize);
    properties.put(JobExecutorXml.KEEP_ALIVE_TIME, keepAliveTime);
    properties.put(JobExecutorXml.MAX_POOL_SIZE, maxPoolSize);
    properties.put(JobExecutorXml.QUEUE_SIZE, queueSize);
    jobExecutorXml.setProperties(properties);
    step.performOperationStep(deploymentOperation);
    PlatformService<JmxManagedThreadPool> service = container.getService(getObjectNameForExecutor());
    ThreadPoolExecutor executor = service.getValue().getThreadPoolExecutor();
    // since no jobs will start, remaining capacity is sufficent to check the size
    assertThat(executor.getQueue().remainingCapacity(), is(Integer.parseInt(queueSize)));
    assertThat(executor.getCorePoolSize(), is(Integer.parseInt(corePoolSize)));
    assertThat(executor.getMaximumPoolSize(), is(Integer.parseInt(maxPoolSize)));
    assertThat(executor.getKeepAliveTime(TimeUnit.MILLISECONDS), is(Long.parseLong(keepAliveTime)));
}
Also used : HashMap(java.util.HashMap) JmxManagedThreadPool(org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 3 with JmxManagedThreadPool

use of org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool in project camunda-bpm-platform by camunda.

the class StartManagedThreadPoolStepTest method performOperationStepWithDefaultProperties.

@Test
public void performOperationStepWithDefaultProperties() {
    Map<String, String> properties = new HashMap<String, String>();
    jobExecutorXml.setProperties(properties);
    step.performOperationStep(deploymentOperation);
    PlatformService<JmxManagedThreadPool> service = container.getService(getObjectNameForExecutor());
    ThreadPoolExecutor executor = service.getValue().getThreadPoolExecutor();
    // since no jobs will start, remaining capacity is sufficent to check the size
    assertThat(executor.getQueue().remainingCapacity(), is(3));
    assertThat(executor.getCorePoolSize(), is(3));
    assertThat(executor.getMaximumPoolSize(), is(10));
    assertThat(executor.getKeepAliveTime(TimeUnit.MILLISECONDS), is(0L));
}
Also used : HashMap(java.util.HashMap) JmxManagedThreadPool(org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Aggregations

ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 JmxManagedThreadPool (org.camunda.bpm.container.impl.jmx.services.JmxManagedThreadPool)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 JobExecutorXml (org.camunda.bpm.container.impl.metadata.spi.JobExecutorXml)1 PlatformServiceContainer (org.camunda.bpm.container.impl.spi.PlatformServiceContainer)1