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

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setQueueCapacity() . 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 seed with Apache License 2.0 6 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("SeedExecutor-");
    executor.setMaxPoolSize(this.maxPoolSize);     //线程池最大数量
    executor.setCorePoolSize(this.corePoolSize);   //线程池最小数量
    executor.setQueueCapacity(this.queueCapacity); //队列大小(最小的线程数被占满后,新任务会放进queue)
    executor.setAwaitTerminationSeconds(60 * 15);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    ////饱和策略:自定义
    //executor.setRejectedExecutionHandler(new RejectedExecutionHandler() {
    //    @Override
    //    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    //        //---------
    //    }
    //});
    //饱和策略:队列满时,使用预定义的异常处理类
    //ABORT(缺省)  :不执行,并抛TaskRejectedException异常
    //DISCARD       :不执行,也不抛异常,直接丢弃任务
    //DISCARD_OLDEST:丢弃queue中最旧的那个任务,并执行当期任务
    //CALLER_RUNS   :不在新线程中执行任务,而是由调用者所在的线程来执行
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.initialize();
    return executor;
}
 
Example 3
Source File: RedisCacheConfig.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
/**
 * 异步方法删除redis缓存的线程池
 */
@Bean("redisTaskExecutor")
public Executor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(50);
    executor.setQueueCapacity(1000);
    executor.setKeepAliveSeconds(60);
    executor.setThreadNamePrefix("delete-redis-cache-");
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return executor;
}
 
Example 4
Source File: AsyncConfiguration.java    From albedo with GNU Lesser General Public License v3.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(taskExecutionProperties.getPool().getCoreSize());
	executor.setMaxPoolSize(taskExecutionProperties.getPool().getMaxSize());
	executor.setQueueCapacity(taskExecutionProperties.getPool().getQueueCapacity());
	executor.setThreadNamePrefix(taskExecutionProperties.getThreadNamePrefix());
	return new ExceptionHandlingAsyncTaskExecutor(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("gateway-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 6
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 7
Source File: SpringConf.java    From joal with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskExecutor taskExecutor() {
    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(25);
    return executor;
}
 
Example 8
Source File: PlowThreadPools.java    From plow with Apache License 2.0 5 votes vote down vote up
/**
 * Handles Async commands from the API.
 */
@Bean(name="stateChangeExecutor")
public ThreadPoolTaskExecutor stateChangeExecutor() {
    ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor();
    t.setCorePoolSize(8);
    t.setMaxPoolSize(16);
    t.setThreadNamePrefix("StateChange");
    t.setDaemon(false);
    t.setQueueCapacity(1000);
    t.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return t;
}
 
Example 9
Source File: AsycTaskExecutorConfig.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskExecutor taskExecutor() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
       executor.setCorePoolSize(corePoolSize);
       executor.setMaxPoolSize(maxPoolSize);
       executor.setQueueCapacity(queueCapacity);
       executor.setThreadNamePrefix("MyExecutor-");

       // rejection-policy:当pool已经达到max size的时候,如何处理新任务
       // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
       executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
       executor.initialize();
       return executor;
}
 
Example 10
Source File: AsyncConfiguration.java    From java-microservices-examples 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(taskExecutionProperties.getPool().getCoreSize());
    executor.setMaxPoolSize(taskExecutionProperties.getPool().getMaxSize());
    executor.setQueueCapacity(taskExecutionProperties.getPool().getQueueCapacity());
    executor.setThreadNamePrefix(taskExecutionProperties.getThreadNamePrefix());
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 11
Source File: CustomExecutorConfig.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	// CUSTOMIZE HERE
	executor.setCorePoolSize(7);
	executor.setMaxPoolSize(42);
	executor.setQueueCapacity(11);
	executor.setThreadNamePrefix("MyExecutor-");
	// DON'T FORGET TO INITIALIZE
	executor.initialize();
	return new LazyTraceExecutor(this.beanFactory, executor);
}
 
Example 12
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("gateway-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(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("uaa-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 14
Source File: FlowableJobConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TaskExecutor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(8);
    executor.setMaxPoolSize(8);
    executor.setQueueCapacity(100);
    executor.setThreadNamePrefix("flowable-task-Executor-");
    executor.setAwaitTerminationSeconds(30);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setAllowCoreThreadTimeOut(true);
    executor.initialize();
    return executor;
}
 
Example 15
Source File: AsyncConfiguration.java    From ServiceCutter with Apache License 2.0 5 votes vote down vote up
@Override
@Bean
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(propertyResolver.getProperty("corePoolSize", Integer.class, 2));
    executor.setMaxPoolSize(propertyResolver.getProperty("maxPoolSize", Integer.class, 50));
    executor.setQueueCapacity(propertyResolver.getProperty("queueCapacity", Integer.class, 10000));
    executor.setThreadNamePrefix("editor-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 16
Source File: ScmAutoConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Bean(BEAN_MVC_EXECUTOR)
public ThreadPoolTaskExecutor mvcTaskExecutor(ScmProperties config) {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(config.getCorePoolSize());
	executor.setQueueCapacity(config.getQueueCapacity());
	executor.setMaxPoolSize(config.getMaxPoolSize());
	return executor;
}
 
Example 17
Source File: AsyncConfiguration.java    From alchemy 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(taskExecutionProperties.getPool().getCoreSize());
    executor.setMaxPoolSize(taskExecutionProperties.getPool().getMaxSize());
    executor.setQueueCapacity(taskExecutionProperties.getPool().getQueueCapacity());
    executor.setThreadNamePrefix(taskExecutionProperties.getThreadNamePrefix());
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 18
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("invoice-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 19
Source File: AsyncConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.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("foo-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 20
Source File: AppConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(name = "asyncExecutor")
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
    executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 3);
    executor.setQueueCapacity(1024);
    executor.setThreadNamePrefix("ASYNCHRONOUS-ANNOTATION-EXECUTOR-");
    executor.initialize();
    return executor;
}