使用taskExecutor(asyncTaskExecutor())时停止spring批处理中的线程
我这里有个问题。当我在spring批处理配置中将其用作我的代码(如下)时,我的代码将成功结束使用taskExecutor(asyncTaskExecutor())时停止spring批处理中的线程,spring,multithreading,spring-batch,Spring,Multithreading,Spring Batch,我这里有个问题。当我在spring批处理配置中将其用作我的代码(如下)时,我的代码将成功结束 @Bean(name = "myStep") public Step myStep() { int cores = Runtime.getRuntime().availableProcessors(); int maxAndQueueSize = cores * 2; return stepBuilderFactory.get("myStep").<A, B> ch
@Bean(name = "myStep")
public Step myStep() {
int cores = Runtime.getRuntime().availableProcessors();
int maxAndQueueSize = cores * 2;
return stepBuilderFactory.get("myStep").<A, B> chunk(CHUNKS)
.reader(myItemReader(entityManagerFactory)).processor(myProcessor())
.writer(myWriter()).listener(myListener()).throttleLimit(maxAndQueueSize).allowStartIfComplete(true).build();
}
这是asyncTaskExecutor()
@Bean(name = "myStep")
public Step myStep() {
int cores = Runtime.getRuntime().availableProcessors();
int maxAndQueueSize = cores * 2;
return stepBuilderFactory.get("myStep").<A, B> chunk(CHUNKS)
.reader(myItemReader(entityManagerFactory)).processor(myProcessor())
.writer(myWriter()).listener(myListener()).taskExecutor(asyncTaskExecutor()).throttleLimit(maxAndQueueSize).allowStartIfComplete(true).build();
}
@Bean(name = "asyncTaskExecutor")
public AsyncTaskExecutor asyncTaskExecutor() {
int cores = Runtime.getRuntime().availableProcessors();
int maxAndQueueSize = cores * 2;
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(cores);
executor.setMaxPoolSize(maxAndQueueSize);
executor.setQueueCapacity(maxAndQueueSize);
executor.setThreadNamePrefix("asyncExecutor-");
executor.initialize();
return executor;
}