Search in sources :

Example 1 with ManagedQueueExecutorService

use of org.jboss.as.threads.ManagedQueueExecutorService in project camunda-bpm-platform by camunda.

the class MscExecutorService method scheduleLongRunningWork.

protected boolean scheduleLongRunningWork(Runnable runnable) {
    final ManagedQueueExecutorService managedQueueExecutorService = managedQueueInjector.getValue();
    boolean rejected = false;
    try {
        // wait for 2 seconds for the job to be accepted by the pool.
        managedQueueExecutorService.executeBlocking(runnable, 2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    // the acquisition thread is interrupted, this probably means the app server is turning the lights off -> ignore
    } catch (ExecutionTimedOutException e) {
        rejected = true;
    } catch (RejectedExecutionException e) {
        rejected = true;
    } catch (Exception e) {
        // if it fails for some other reason, log a warning message
        long now = System.currentTimeMillis();
        // only log every 60 seconds to prevent log flooding
        if ((now - lastWarningLogged) >= (60 * 1000)) {
            log.log(Level.WARNING, "Unexpected Exception while submitting job to executor pool.", e);
        } else {
            log.log(Level.FINE, "Unexpected Exception while submitting job to executor pool.", e);
        }
    }
    return !rejected;
}
Also used : ManagedQueueExecutorService(org.jboss.as.threads.ManagedQueueExecutorService) ExecutionTimedOutException(org.jboss.threads.ExecutionTimedOutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionTimedOutException(org.jboss.threads.ExecutionTimedOutException) StartException(org.jboss.msc.service.StartException)

Example 2 with ManagedQueueExecutorService

use of org.jboss.as.threads.ManagedQueueExecutorService in project camunda-bpm-platform by camunda.

the class JBossSubsystemXMLTest method testInstallSubsystemWithJobExecutorAndPropertiesXml.

@Test
public void testInstallSubsystemWithJobExecutorAndPropertiesXml() throws Exception {
    String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_JOB_EXECUTOR_AND_PROPERTIES);
    KernelServices services = createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
    ServiceContainer container = services.getContainer();
    commonSubsystemServicesAreInstalled(container);
    // "default" job acquisition ///////////////////////////////////////////////////////////
    ServiceController<?> defaultJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("default"));
    assertNotNull("platform job acquisition service 'default' should be installed", defaultJobAcquisitionService);
    Object value = defaultJobAcquisitionService.getValue();
    assertNotNull(value);
    assertTrue(value instanceof JobExecutor);
    JobExecutor defaultJobExecutor = (JobExecutor) value;
    assertEquals(300000, defaultJobExecutor.getLockTimeInMillis());
    assertEquals(5000, defaultJobExecutor.getWaitTimeInMillis());
    assertEquals(3, defaultJobExecutor.getMaxJobsPerAcquisition());
    // ServiceName: 'org.camunda.bpm.platform.job-executor.job-executor-tp'
    ServiceController<ManagedQueueExecutorService> managedQueueExecutorServiceController = (ServiceController<ManagedQueueExecutorService>) container.getService(ServiceNames.forManagedThreadPool(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
    assertNotNull(managedQueueExecutorServiceController);
    ManagedQueueExecutorService managedQueueExecutorService = managedQueueExecutorServiceController.getValue();
    assertNotNull(managedQueueExecutorService);
    assertEquals("Number of core threads is wrong", SubsystemAttributeDefinitons.DEFAULT_CORE_THREADS, managedQueueExecutorService.getCoreThreads());
    assertEquals("Number of max threads is wrong", SubsystemAttributeDefinitons.DEFAULT_MAX_THREADS, managedQueueExecutorService.getMaxThreads());
    assertEquals(SubsystemAttributeDefinitons.DEFAULT_KEEPALIVE_TIME, TimeUnit.NANOSECONDS.toSeconds(managedQueueExecutorService.getKeepAlive()));
    assertEquals(false, managedQueueExecutorService.isBlocking());
    assertEquals(SubsystemAttributeDefinitons.DEFAULT_ALLOW_CORE_TIMEOUT, managedQueueExecutorService.isAllowCoreTimeout());
    ServiceController<ThreadFactoryService> threadFactoryService = (ServiceController<ThreadFactoryService>) container.getService(ServiceNames.forThreadFactoryService(SubsystemAttributeDefinitons.DEFAULT_JOB_EXECUTOR_THREADPOOL_NAME));
    assertNotNull(threadFactoryService);
    // "anders" job acquisition /////////////////////////////////////////////////////////
    ServiceController<?> andersJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("anders"));
    assertNotNull("platform job acquisition service 'anders' should be installed", andersJobAcquisitionService);
    value = andersJobAcquisitionService.getValue();
    assertNotNull(value);
    assertTrue(value instanceof JobExecutor);
    JobExecutor andersJobExecutor = (JobExecutor) value;
    assertEquals(600000, andersJobExecutor.getLockTimeInMillis());
    assertEquals(10000, andersJobExecutor.getWaitTimeInMillis());
    assertEquals(5, andersJobExecutor.getMaxJobsPerAcquisition());
    // "mixed" job acquisition /////////////////////////////////////////////////////////
    ServiceController<?> mixedJobAcquisitionService = container.getService(ServiceNames.forMscRuntimeContainerJobExecutorService("mixed"));
    assertNotNull("platform job acquisition service 'mixed' should be installed", mixedJobAcquisitionService);
    value = mixedJobAcquisitionService.getValue();
    assertNotNull(value);
    assertTrue(value instanceof JobExecutor);
    JobExecutor mixedJobExecutor = (JobExecutor) value;
    assertEquals(500000, mixedJobExecutor.getLockTimeInMillis());
    // default values
    assertEquals(5000, mixedJobExecutor.getWaitTimeInMillis());
    assertEquals(3, mixedJobExecutor.getMaxJobsPerAcquisition());
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) ManagedQueueExecutorService(org.jboss.as.threads.ManagedQueueExecutorService) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) ThreadFactoryService(org.jboss.as.threads.ThreadFactoryService) KernelServices(org.jboss.as.subsystem.test.KernelServices) ServiceController(org.jboss.msc.service.ServiceController) AbstractSubsystemTest(org.jboss.as.subsystem.test.AbstractSubsystemTest) Test(org.junit.Test)

Example 3 with ManagedQueueExecutorService

use of org.jboss.as.threads.ManagedQueueExecutorService 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

ManagedQueueExecutorService (org.jboss.as.threads.ManagedQueueExecutorService)3 ThreadFactoryService (org.jboss.as.threads.ThreadFactoryService)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1 AbstractSubsystemTest (org.jboss.as.subsystem.test.AbstractSubsystemTest)1 KernelServices (org.jboss.as.subsystem.test.KernelServices)1 BoundedQueueThreadPoolService (org.jboss.as.threads.BoundedQueueThreadPoolService)1 TimeSpec (org.jboss.as.threads.TimeSpec)1 ServiceContainer (org.jboss.msc.service.ServiceContainer)1 ServiceController (org.jboss.msc.service.ServiceController)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 StartException (org.jboss.msc.service.StartException)1 ExecutionTimedOutException (org.jboss.threads.ExecutionTimedOutException)1 Test (org.junit.Test)1