编程语言
首页 > 编程语言> > 【JUC编程】守护线程

【JUC编程】守护线程

作者:互联网

概念:


示例:

/**
 * @author jitwxs
 * @date 2021年04月13日 16:49
 */
public class Caraful {

        public static void main(String[] args) {
                God god=new God();
                I my=new I();
                Thread threadG=new Thread(god);
                threadG.setDaemon(true); //设置为守护线程
                threadG.start();
                new Thread(my).start();

        }

        static class God implements Runnable{

                @Override
                public void run() {
                        while (true){
                                System.out.println("god is key");
                        }
                }
        }

        static class I implements Runnable{
                @Override
                public void run() {
                        for (int i = 0; i < 50; i++) {
                                System.out.println("第"+i+"天");

                        }
                }
        }


}

标签:JUC,God,编程,static,线程,god,new,public
来源: https://blog.csdn.net/m0_46495243/article/details/115673668