fix 修复 关闭应用找不到线程池bean问题

2.X
疯狂的狮子Li 1 year ago
parent e926953de0
commit b4f7838949

@ -26,14 +26,15 @@ import java.util.concurrent.*;
@AutoConfiguration
public class AsyncConfig implements AsyncConfigurer {
private static final int CORE_POOL_SIZE = 10;
private final int corePoolSize = Runtime.getRuntime().availableProcessors() + 1;
private ScheduledExecutorService scheduledExecutorService;
/**
*
*/
@Bean(name = "scheduledExecutorService")
public ScheduledExecutorService scheduledExecutorService() {
return new ScheduledThreadPoolExecutor(CORE_POOL_SIZE,
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(corePoolSize,
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
new ThreadPoolExecutor.CallerRunsPolicy()) {
@Override
@ -42,6 +43,8 @@ public class AsyncConfig implements AsyncConfigurer {
printException(r, t);
}
};
this.scheduledExecutorService = scheduledThreadPoolExecutor;
return scheduledThreadPoolExecutor;
}
/**
@ -51,7 +54,6 @@ public class AsyncConfig implements AsyncConfigurer {
public void destroy() {
try {
log.info("====关闭后台任务任务线程池====");
ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
Threads.shutdownAndAwaitTermination(scheduledExecutorService);
} catch (Exception e) {
log.error(e.getMessage(), e);

Loading…
Cancel
Save