美文网首页
多线程-守护线程

多线程-守护线程

作者: QQ_33e9 | 来源:发表于2019-03-02 21:54 被阅读0次

    守护线程特点:随着调用线程的停止而销毁。

    设置守护线程,setDaemon(true);

    public class Main{

        public static void main(String args[]){

            Thread t = new Thread(){

                public void run(){

                    int i = 1;

                    while(true){

                        System.out.println(i++);

                    }

                }

            };

           t.setDaemon(true);

            t.start();

            System.out.println("main");

        }

    }

    相关文章

      网友评论

          本文标题:多线程-守护线程

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