破坏@bean创建的执行者

时间:2018-04-05 08:15:35

标签: spring spring-annotations spring-async

我在Spring 4中有以下annotationconfig

    @Bean(name = "replicationThreadExecutor")
public Executor replicationThreadExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(threadPoolCoreSize);
    executor.setMaxPoolSize(threadPoolCoreSize);
    executor.initialize();
    return executor;
}

我关心的是Executor的毁灭。 Spring会认识到Executor的动态类型是DisposableBean的一个实例并将其销毁,还是我需要将返回类型更改为ThreadPoolTaskExecutor才能使其生效?

1 个答案:

答案 0 :(得分:0)

如果在registerShutdownHook上调用ConfigurableApplicationContext方法,则会调用单个bean上的所有销毁方法