Turning an ExecutorService to daemon in Java

后端 未结 8 2272
无人共我
无人共我 2020-11-27 02:39

I am using an ExecutoreService in Java 1.6, started simply by

ExecutorService pool = Executors.newFixedThreadPool(THREADS). 

When my main

8条回答
  •  长情又很酷
    2020-11-27 03:02

    I would use Guava's ThreadFactoryBuilder class.

    ExecutorService threadPool = Executors.newFixedThreadPool(THREADS, new ThreadFactoryBuilder().setDaemon(true).build());
    

    If you're not already using Guava, I'd go with a ThreadFactory subclass like described at the top of Pshemo's answer

提交回复
热议问题