Java 如何在Spring Boot中关闭ThreadPoolTaskExecutor的特定任务(进程)?

Java 如何在Spring Boot中关闭ThreadPoolTaskExecutor的特定任务(进程)?,java,spring,spring-boot,Java,Spring,Spring Boot,大家好 我想终止或关闭ThreadPoolTaskExecutor中的特定任务 e、 g。 我想为我将要排队的每个任务设置一个唯一的id或名称,然后使用我添加到此任务的id或名称将其关闭 这是因为我有用户,我的应用程序用例迫使我为每个用户指定任务,但有时我想关闭特定用户的特定任务 比如说 以及关闭 taskExecutor.shutDownTaskById('john-deo-1521'); 这是我对ThreadPoolTaskExecutor的主要配置 @Configuration @Ena

大家好

我想终止或关闭ThreadPoolTaskExecutor中的特定任务

e、 g。 我想为我将要排队的每个任务设置一个唯一的id或名称,然后使用我添加到此任务的id或名称将其关闭

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

比如说

以及关闭

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;

    }
}

这个链接可以帮助你:这个链接可以帮助你:
@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;

    }
}