1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| @Configuration @EnableAsync
public class NativeAsyncTaskExecutePool implements AsyncConfigurer{
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired TaskThreadPoolConfig config; @Override public Executor getAsyncExecutor(){ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(config.getCorePoolSize());
executor.setMaxPoolSize(config.getMaxPoolSize());
executor.setQueueCapacity(config.getQueueCapacity());
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
executor.setThreadNamePrefix("MyExecutor2-"); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize();
return executor; }
@Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler(){
return (ex, method, objects) -> { logger.error("=========================="+ex.getMessage()+"=======================", ex); logger.error("exception method:"+method.getName()); }; } }
|