zoukankan      html  css  js  c++  java
  • 多线程06.thread守护线程

    package chapter2;
    
    public class Demo02 {
        public static void main(String[] args) {
    Thread th1=new Thread(){
        @Override
        public void run() {
            //主线程
            Thread th2=new Thread(){
    
                //守护线程
                @Override
                public void run() {
                    try {
                        Thread.sleep(1_000);
                        System.out.println("T thread finish done.");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
    
                }
            };
           // 当th1.setDaemon(true),即t为Daemon线程时,主线程结束,守护线程也结束
            th2.setDaemon(true);
            th2.start();
            try { while (true) {
                System.out.println("Do some thing for health check.");
                Thread.sleep(1_000);
            }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
        }
    };
                th1.start();
    
    
    
        }
    }
  • 相关阅读:
    Linux 工具命令
    Js的一些工具方法
    使用curl测试网络通信
    python 创建XML
    Nginx 使用Lua脚本
    lua 安装cjson
    3对象和类_动手动脑
    10.5
    10.4动手动脑
    10.2
  • 原文地址:https://www.cnblogs.com/q1359720840/p/10651699.html
Copyright © 2011-2022 走看看