美文网首页数客联盟Growing
ExecutorService启动守护线程

ExecutorService启动守护线程

作者: Woople | 来源:发表于2019-01-17 07:54 被阅读2次

    通常使用ExecutorService pool = Executors.newFixedThreadPool(1)方式创建一个线程池,但是这个线程池里面的线程都是非守护线程,如何将线程设置为守护线程,下面代码参考apache shiro

    ExecutorService pool = Executors.newFixedThreadPool(1, 
        new ThreadFactory() {  
            public Thread newThread(Runnable r) {  
                Thread thread = new Thread(r);  
                thread.setDaemon(true);  
                thread.setName(threadNamePrefix + thread.getId());
                return thread;  
            }  
        });     
    

    相关文章

      网友评论

        本文标题:ExecutorService启动守护线程

        本文链接:https://www.haomeiwen.com/subject/ggdbdqtx.html