Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用taskExecutor(asyncTaskExecutor())时停止spring批处理中的线程_Spring_Multithreading_Spring Batch - Fatal编程技术网

使用taskExecutor(asyncTaskExecutor())时停止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

我这里有个问题。当我在spring批处理配置中将其用作我的代码(如下)时,我的代码将成功结束

@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;
}