mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化 简化线程池配置
This commit is contained in:
		@@ -1,8 +1,11 @@
 | 
			
		||||
package org.dromara.common.core.config;
 | 
			
		||||
 | 
			
		||||
import jakarta.annotation.PreDestroy;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.dromara.common.core.config.properties.ThreadPoolProperties;
 | 
			
		||||
import org.dromara.common.core.utils.Threads;
 | 
			
		||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Qualifier;
 | 
			
		||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
 | 
			
		||||
@@ -18,6 +21,7 @@ import java.util.concurrent.ThreadPoolExecutor;
 | 
			
		||||
 *
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 **/
 | 
			
		||||
@Slf4j
 | 
			
		||||
@AutoConfiguration
 | 
			
		||||
@EnableConfigurationProperties(ThreadPoolProperties.class)
 | 
			
		||||
public class ThreadPoolConfig {
 | 
			
		||||
@@ -54,4 +58,18 @@ public class ThreadPoolConfig {
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 销毁事件
 | 
			
		||||
     */
 | 
			
		||||
    @PreDestroy
 | 
			
		||||
    public void destroy(@Qualifier("scheduledExecutorService") ScheduledExecutorService scheduledExecutorService) {
 | 
			
		||||
        try {
 | 
			
		||||
            log.info("====关闭后台任务任务线程池====");
 | 
			
		||||
            Threads.shutdownAndAwaitTermination(scheduledExecutorService);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error(e.getMessage(), e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,41 +0,0 @@
 | 
			
		||||
package org.dromara.common.core.manager;
 | 
			
		||||
 | 
			
		||||
import org.dromara.common.core.utils.Threads;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Qualifier;
 | 
			
		||||
import org.springframework.stereotype.Component;
 | 
			
		||||
 | 
			
		||||
import jakarta.annotation.PreDestroy;
 | 
			
		||||
import java.util.concurrent.ScheduledExecutorService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 确保应用退出时能关闭后台线程
 | 
			
		||||
 *
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
@Component
 | 
			
		||||
public class ShutdownManager {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    @Qualifier("scheduledExecutorService")
 | 
			
		||||
    private ScheduledExecutorService scheduledExecutorService;
 | 
			
		||||
 | 
			
		||||
    @PreDestroy
 | 
			
		||||
    public void destroy() {
 | 
			
		||||
        shutdownAsyncManager();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 停止异步执行任务
 | 
			
		||||
     */
 | 
			
		||||
    private void shutdownAsyncManager() {
 | 
			
		||||
        try {
 | 
			
		||||
            log.info("====关闭后台任务任务线程池====");
 | 
			
		||||
            Threads.shutdownAndAwaitTermination(scheduledExecutorService);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error(e.getMessage(), e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user