Spring boot 生成线程池
程序员文章站
2022-05-01 13:03:53
...
@Configuration
public class ConvertThreadPoolConfig {
private static final AtomicInteger threadIndex = new AtomicInteger(0);
@Bean(value = "convertThreadPool")
public ExecutorService convertThreadPool() {
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, "convert-thread-" + threadIndex.incrementAndGet());
thread.setDaemon(true);
return thread;
}
};
ExecutorService pool = new ThreadPoolExecutor(2, 4, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10), threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
return pool;
}
}