Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setCorePoolSize()

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setCorePoolSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultJobConfiguration.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Bean(name = CAMUNDA_TASK_EXECUTOR_QUALIFIER)
@ConditionalOnMissingBean(name = CAMUNDA_TASK_EXECUTOR_QUALIFIER)
@ConditionalOnProperty(prefix = "camunda.bpm.job-execution", name = "enabled", havingValue = "true", matchIfMissing = true)
public static TaskExecutor camundaTaskExecutor(CamundaBpmProperties properties) {
  int corePoolSize = properties.getJobExecution().getCorePoolSize();
  int maxPoolSize = properties.getJobExecution().getMaxPoolSize();
  int queueCapacity = properties.getJobExecution().getQueueCapacity();

  final ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();

  threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
  threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
  threadPoolTaskExecutor.setQueueCapacity(queueCapacity);

  Optional.ofNullable(properties.getJobExecution().getKeepAliveSeconds())
    .ifPresent(threadPoolTaskExecutor::setKeepAliveSeconds);

  LOG.configureJobExecutorPool(corePoolSize, maxPoolSize);
  return threadPoolTaskExecutor;
}
 
Example 2
Source File: AsyncConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("uaa-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 3
Source File: FlowRunnerTaskExecutorSupplier.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Override
default TaskExecutor get() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(4);
	executor.initialize();
	return executor;
}
 
Example 4
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public AsyncTaskExecutor intermediateBuilderExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(intermediateCorePoolSize);
    executor.setQueueCapacity(intermediateQueueCapacity);
    executor.setThreadNamePrefix("intermediateBuilderExecutor-");
    executor.setTaskDecorator(new MDCCleanerTaskDecorator());
    executor.initialize();
    return executor;
}
 
Example 5
Source File: AsyncConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("dealerapp-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 6
Source File: AsyncTaskConfig.java    From plumemo with Apache License 2.0 5 votes vote down vote up
/**
 * 配置线程信息
 */
@Bean(name = "asyncExecutor")
public Executor asyncExecutor() {
    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(3);
    executor.setMaxPoolSize(3);
    executor.setQueueCapacity(100);
    //拒绝策略:如果执行程序已关闭,则会丢弃该任务
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.setThreadNamePrefix("HELL0-BLOG-Task-");
    executor.initialize();
    return executor;
}
 
Example 7
Source File: AsyncExecutorPoolConfig.java    From FEBS-Security with Apache License 2.0 5 votes vote down vote up
@Bean
public Executor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(20);
    executor.setQueueCapacity(100);
    executor.setKeepAliveSeconds(30);
    executor.setThreadNamePrefix("asyncTaskExecutor-");

    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return executor;
}
 
Example 8
Source File: AsyncConfiguration.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Bean(name = "asyncExecutor")
public Executor asyncExecutor() {
  final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  executor.setCorePoolSize(3);
  executor.setMaxPoolSize(3);
  executor.setQueueCapacity(100);
  executor.setThreadNamePrefix("AsynchThread-");
  executor.initialize();
  return executor;
}
 
Example 9
Source File: ThreadPoolTaskExecutorUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCorePoolSizeFiveAndMaxPoolSizeTenAndQueueCapacityTen_thenTenThreads() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(5);
    taskExecutor.setMaxPoolSize(10);
    taskExecutor.setQueueCapacity(10);
    taskExecutor.afterPropertiesSet();

    CountDownLatch countDownLatch = new CountDownLatch(20);
    this.startThreads(taskExecutor, countDownLatch, 20);

    while (countDownLatch.getCount() > 0) {
        Assert.assertEquals(10, taskExecutor.getPoolSize());
    }
}
 
Example 10
Source File: Application.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
   ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
   executor.setThreadNamePrefix("sse-");
   executor.setCorePoolSize(2);
   executor.setMaxPoolSize(100);
   executor.setQueueCapacity(5);
   executor.initialize();
   return executor;
}
 
Example 11
Source File: AsyncConfig.java    From SpringBootMultiTenancy with MIT License 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

    executor.setCorePoolSize(7);
    executor.setMaxPoolSize(42);
    executor.setQueueCapacity(11);
    executor.setThreadNamePrefix("TenantAwareTaskExecutor-");
    executor.setTaskDecorator(new TenantAwareTaskDecorator());
    executor.initialize();

    return executor;
}
 
Example 12
Source File: AppConfig.java    From staffjoy with MIT License 5 votes vote down vote up
@Bean(name=ASYNC_EXECUTOR_NAME)
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(appProps.getConcurrency());
    executor.setMaxPoolSize(appProps.getConcurrency());
    executor.setQueueCapacity(SmsConstant.DEFAULT_EXECUTOR_QUEUE_CAPACITY);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("AsyncThread-");
    executor.initialize();
    return executor;
}
 
Example 13
Source File: AsyncConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("bookstore-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 14
Source File: ServiceSpringModuleConfig.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Activiti's dedicated TaskExecutor bean definition.
 *
 * @return TaskExecutor
 */
@Bean
public TaskExecutor activitiTaskExecutor()
{
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_CORE_POOL_SIZE, Integer.class));
    taskExecutor.setMaxPoolSize(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_MAX_POOL_SIZE, Integer.class));
    taskExecutor.setKeepAliveSeconds(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_KEEP_ALIVE_SECS, Integer.class));
    taskExecutor.setQueueCapacity(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_QUEUE_CAPACITY, Integer.class));
    return taskExecutor;
}
 
Example 15
Source File: ChatController.java    From Mastering-Distributed-Tracing with MIT License 5 votes vote down vote up
@Bean
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(2);
    executor.setMaxPoolSize(2);
    executor.setQueueCapacity(10);
    executor.setThreadNamePrefix("send-to-kafka-");
    executor.initialize();
    return executor;
}
 
Example 16
Source File: AsyncConfiguration.java    From e-commerce-microservice with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("notification-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 17
Source File: Application.java    From blog-non-blocking-rest-service-with-spring-mvc with Apache License 2.0 5 votes vote down vote up
@Bean(name="dbThreadPoolExecutor")
public TaskExecutor getTaskExecutor() {
    ThreadPoolTaskExecutor tpte = new ThreadPoolTaskExecutor();
    tpte.setCorePoolSize(THREAD_POOL_DB_INIT_SIZE);
    tpte.setMaxPoolSize(THREAD_POOL_DB_MAX_SIZE);
    tpte.setQueueCapacity(THREAD_POOL_DB_QUEUE_SIZE);
    tpte.initialize();
    return tpte;
}
 
Example 18
Source File: AsyncConfig.java    From SpringBoot2.0 with Apache License 2.0 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    //核心线程数
    taskExecutor.setCorePoolSize(8);
    //最大线程数
    taskExecutor.setMaxPoolSize(16);
    //队列大小
    taskExecutor.setQueueCapacity(100);
    taskExecutor.setThreadNamePrefix("my-pool-");
    taskExecutor.initialize();
    return taskExecutor;
}
 
Example 19
Source File: PerformanceDTTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Stress tests that create tx and sign them
 *
 * @param totalSignedTxCount
 * @param threadC
 * @throws InterruptedException
 */
public void userTransferSignTxPerfTest(BigInteger totalSignedTxCount, int threadC)
        throws InterruptedException {

    ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();

    threadPool.setCorePoolSize(threadC > 0 ? threadC : 10);
    threadPool.setMaxPoolSize(threadC > 0 ? threadC : 10);
    threadPool.setQueueCapacity(threadC > 0 ? threadC : 10);
    threadPool.initialize();

    Credentials credentials = GenCredential.create();

    TransferSignTransactionManager extendedRawTransactionManager =
            new TransferSignTransactionManager(
                    null, credentials, BigInteger.ONE, BigInteger.ONE);

    dagTransfer =
            DagTransfer.load(
                    dagTransferAddr,
                    null,
                    extendedRawTransactionManager,
                    new StaticGasProvider(
                            new BigInteger("30000000"), new BigInteger("30000000")));

    AtomicLong signed = new AtomicLong(0);

    long startTime = System.currentTimeMillis();
    System.out.println(" => " + dateFormat.format(new Date()));

    for (int i = 0; i < threadC; i++) {
        threadPool.execute(
                new Runnable() {
                    @Override
                    public void run() {
                        while (true) {

                            long index = signed.incrementAndGet();
                            if (index > totalSignedTxCount.intValue()) {
                                break;
                            }
                            DagTransferUser from = dagUserMgr.getFrom((int) index);
                            DagTransferUser to = dagUserMgr.getTo((int) index);

                            Random random = new Random();
                            int r = random.nextInt(100) + 1;
                            BigInteger amount = BigInteger.valueOf(r);

                            try {
                                String signedTransaction =
                                        dagTransfer.userTransferSeq(
                                                from.getUser(), to.getUser(), amount);

                                if (index % (totalSignedTxCount.longValue() / 10) == 0) {
                                    System.out.println(
                                            "Signed transaction: "
                                                    + String.valueOf(
                                                            index
                                                                    * 100
                                                                    / totalSignedTxCount
                                                                            .longValue())
                                                    + "%");
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                System.exit(-1);
                            }
                        }
                    }
                });
    }

    while (signed.get() < totalSignedTxCount.intValue()) {
        Thread.sleep(10);
    }

    long endTime = System.currentTimeMillis();
    double elapsed = (endTime - startTime) / 1000.0;

    System.out.println(" => " + dateFormat.format(new Date()));

    System.out.print(
            " sign transactions finished, elapse time: "
                    + elapsed
                    + ", tx count = "
                    + totalSignedTxCount
                    + " ,sps = "
                    + (totalSignedTxCount.intValue() / elapsed));
    System.exit(0);
}
 
Example 20
Source File: StateMachineTests.java    From spring-cloud-skipper with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskExecutor skipperStateMachineTaskExecutor() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(1);
	return executor;
}