如何在Spring Boot中关闭ThreadPoolTask​​Executor的特定任务(进程)?

时间:2020-01-05 11:20:46

标签: java spring spring-boot

大家好

我想终止或关闭ThreadPoolTask​​Executor中的特定任务

例如 我想为每个任务设置一个唯一的ID或名称,然后将其排队,然后使用添加到此任务的ID或名称将其关闭

那是因为我有用户,而我的应用程序用例迫使我为每个用户指定任务,但有时我想关闭特定用户的特定任务

例如

user.setTaskId('john-deo-1521');
user.setTaskId('john-deo-1522');

并用于关闭

taskExecutor.shutDownTaskById('john-deo-1521');

这是我对ThreadPoolTask​​Executor的主要配置

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

    }
}

0 个答案:

没有答案