线程池命名

public static void main(String[] args) throws Exception {
        //创建线程池
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-call-runner-%d").build();

        ExecutorService executorService = Executors.newFixedThreadPool(8, namedThreadFactory);
        for(int i=0;i<100;i++){
            executorService.execute(()->{
                System.out.println(Thread.currentThread().getName()+"333");
            });
        }

        executorService.shutdown();
    }

 

posted @ 2022-07-14 18:50  动力起点  阅读(236)  评论(0编辑  收藏  举报