大家好
我想终止或关闭ThreadPoolTaskExecutor中的特定任务
例如 我想为每个任务设置一个唯一的ID或名称,然后将其排队,然后使用添加到此任务的ID或名称将其关闭
那是因为我有用户,而我的应用程序用例迫使我为每个用户指定任务,但有时我想关闭特定用户的特定任务
例如
user.setTaskId('john-deo-1521');
user.setTaskId('john-deo-1522');
并用于关闭
taskExecutor.shutDownTaskById('john-deo-1521');
这是我对ThreadPoolTaskExecutor的主要配置
@Configuration
@EnableAsync
public class ServiceExecutorConfig implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(30);
taskExecutor.setMaxPoolSize(40);
taskExecutor.setQueueCapacity(10);
taskExecutor.initialize();
return taskExecutor;
}
}