fix 修复 关闭应用找不到线程池bean问题
parent
e926953de0
commit
b4f7838949
|
|
@ -26,14 +26,15 @@ import java.util.concurrent.*;
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
public class AsyncConfig implements AsyncConfigurer {
|
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")
|
@Bean(name = "scheduledExecutorService")
|
||||||
public ScheduledExecutorService 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 BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -42,6 +43,8 @@ public class AsyncConfig implements AsyncConfigurer {
|
||||||
printException(r, t);
|
printException(r, t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.scheduledExecutorService = scheduledThreadPoolExecutor;
|
||||||
|
return scheduledThreadPoolExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,7 +54,6 @@ public class AsyncConfig implements AsyncConfigurer {
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
try {
|
try {
|
||||||
log.info("====关闭后台任务任务线程池====");
|
log.info("====关闭后台任务任务线程池====");
|
||||||
ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
||||||
Threads.shutdownAndAwaitTermination(scheduledExecutorService);
|
Threads.shutdownAndAwaitTermination(scheduledExecutorService);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue