zoukankan      html  css  js  c++  java
  • 笔记20200521001:多线程【守护线程】

    package com.chengguo.线程;
    
    /**
     * 线程守护【举例:上帝守护人类】
     */
    public class Demo_20200522001_Daemon {
        public static void main(String[] args) {
            //创建线程
            God god = new God();
            Human human = new Human();
    
            Thread thread = new Thread(god);
            thread.setDaemon(true);//默认为false
    
            //上帝 守护线程启动
            thread.start();
            //human 线程启动
            new Thread(human).start();
        }
    
    
    }
    
    //上帝--->类
    class God implements Runnable {
        @Override
        public void run() {
            while (true)
                System.out.println();
        }
    }
    
    //人类--->类
    class Human implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 36500; i++) {
                System.out.println("人类苟且活着……");
            }
            System.out.println("再见,这个美丽的世界……");
        }
    }
    

      

     
  • 相关阅读:
    project和task
    Gradle的安装
    Spring 集成 RMI
    RMI远程调用
    安装、启动与基本配置
    删除
    文件的分隔与合并
    my27_OGG MySQL To MySQL错误汇总
    1.5 GO json转Map
    1.4 Go语言-switch语句(转)
  • 原文地址:https://www.cnblogs.com/sadfoo/p/13128679.html
Copyright © 2011-2022 走看看