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