我在这里有一个问题。当我在Spring批量配置中使用它作为我的代码(下面)时,我的代码成功结束。
taskExecutor(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();
}
来修改此代码(用于异步写入)时,我的目标已实现,但代码仍在eclipse中运行。似乎是一个关闭相关问题的线程。请帮助我如何优雅地关闭我的代码?
@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;
}
这是asyncTaskExecutor()
{{1}}