zoukankan      html  css  js  c++  java
  • Java多线程(六)守护进程

    守护进程:当进程中不存在非守护线程了,则守护线程自动销毁;

    public class DaemonThread extends Thread{
    
        private int i =0;
        public void run(){
            try {
                while(true){
                    i++;
                    System.out.println("i="+i);
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                System.out.println("test");
                e.printStackTrace();
            }
        }
        
        public static void main(String[] args) throws InterruptedException {
            DaemonThread thread = new DaemonThread();
            thread.setDaemon(true);
            thread.start();
            Thread.sleep(2000);
            System.out.println("我离开thread对象也不再打印了,也就是停止了!");
        }
    }
  • 相关阅读:
    Visual Studio 2015 密钥
    Vue-next源码新鲜出炉一
    vue2.0基础整理
    Nest
    Nest
    Nest
    Nest
    Nest快速上手
    element-plus源码分析第一节
    获取视频第一帧,作为封面图
  • 原文地址:https://www.cnblogs.com/newlangwen/p/7595487.html
Copyright © 2011-2022 走看看