// 线程工厂,用于为线程池中的每条线程命名
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("judge-pool-%d")
.setUncaughtExceptionHandler((thread, throwable)-> logger.error("ThreadPool {} got exception", thread,throwable))
.build();
// 创建线程池,使用有界阻塞队列防止内存溢出
ExecutorService statsThreadPool = new ThreadPoolExecutor(5, 10,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(100), namedThreadFactory);
// 遍历所有中心,为每一个centerId提交一条任务到线程池
statsThreadPool.submit(new StatsJob(centerId));
线程池自定义异常处理方法
猜你喜欢
转载自blog.csdn.net/xx897115293/article/details/108533263
今日推荐
周排行