这两个ThreadPoolTask​​Executors可以相互影响吗?

时间:2018-06-12 12:51:13

标签: spring multithreading tomcat threadpool threadpoolexecutor

我有两个ThreadPoolExecutors。第一个,在afterPropertiesSet()

中以这种方式初始化一次
ThreadPoolTaskExecutor firstTaskExecutor = null;

然后

this.firstTaskExecutor= new ThreadPoolTaskExecutor();
this.firstTaskExecutor.setBeanName("reports");
this.firstTaskExecutor.setMaxPoolSize(3);
this.firstTaskExecutor.setQueueCapacity(200);
this.firstTaskExecutor
            .setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
this.firstTaskExecutor.afterPropertiesSet();
this.firstTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);

第二个是通过其他控制器中的Bean连线:

@Bean
public TaskExecutor threadPoolTaskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(4);
    executor.setMaxPoolSize(4);
    executor.setThreadNamePrefix("EMAILS");
    executor.initialize();
    return executor;
}

将第二个添加到代码后,第一个TaskExecutor执行的所有任务似乎只由一个线程处理,这意味着第二个池正在影响第一个。

这可能是这个原因吗?

0 个答案:

没有答案