mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	fix 修复 关闭应用找不到线程池bean问题
This commit is contained in:
		@@ -4,7 +4,6 @@ import jakarta.annotation.PreDestroy;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
 | 
			
		||||
import org.dromara.common.core.config.properties.ThreadPoolProperties;
 | 
			
		||||
import org.dromara.common.core.utils.SpringUtils;
 | 
			
		||||
import org.dromara.common.core.utils.Threads;
 | 
			
		||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
@@ -31,6 +30,8 @@ public class ThreadPoolConfig {
 | 
			
		||||
     */
 | 
			
		||||
    private final int core = Runtime.getRuntime().availableProcessors() + 1;
 | 
			
		||||
 | 
			
		||||
    private ScheduledExecutorService scheduledExecutorService;
 | 
			
		||||
 | 
			
		||||
    @Bean(name = "threadPoolTaskExecutor")
 | 
			
		||||
    @ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true")
 | 
			
		||||
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(ThreadPoolProperties threadPoolProperties) {
 | 
			
		||||
@@ -48,7 +49,7 @@ public class ThreadPoolConfig {
 | 
			
		||||
     */
 | 
			
		||||
    @Bean(name = "scheduledExecutorService")
 | 
			
		||||
    protected ScheduledExecutorService scheduledExecutorService() {
 | 
			
		||||
        return new ScheduledThreadPoolExecutor(core,
 | 
			
		||||
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(core,
 | 
			
		||||
            new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
 | 
			
		||||
            new ThreadPoolExecutor.CallerRunsPolicy()) {
 | 
			
		||||
            @Override
 | 
			
		||||
@@ -57,6 +58,8 @@ public class ThreadPoolConfig {
 | 
			
		||||
                Threads.printException(r, t);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        this.scheduledExecutorService = scheduledThreadPoolExecutor;
 | 
			
		||||
        return scheduledThreadPoolExecutor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -66,7 +69,6 @@ public class ThreadPoolConfig {
 | 
			
		||||
    public void destroy() {
 | 
			
		||||
        try {
 | 
			
		||||
            log.info("====关闭后台任务任务线程池====");
 | 
			
		||||
            ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
 | 
			
		||||
            Threads.shutdownAndAwaitTermination(scheduledExecutorService);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error(e.getMessage(), e);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user