通过借助spring的bean的初始化实现自定义线程池
private ExecutorService executor;
@PostConstruct
public void init() {
executor =
new ThreadMdcUtil.ThreadPoolExecutorMdcWrapper(10, 10, 5, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1024),
r -> new Thread(r, "task-dispatch-thread"), new ThreadPoolExecutor.AbortPolicy());
}
@PreDestroy
public void destroy() {
if (Objects.nonNull(executor)) {
executor.shutdownNow();
}
}