zoukankan      html  css  js  c++  java
  • 一个例子让你懂java里面的守护线程

    例子如下:

    public class DemoThread {
        public static void main(String[] args) throws InterruptedException {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true){
                        System.out.println("hello daemon thread");
                    }
                }
            });
            thread.setDaemon(true);   //这一行去掉之后,JVM会一直运行,守护线程会随着主线程死亡而死亡
            thread.start();
    
            Thread.sleep(3000);
        }
    }
  • 相关阅读:
    文件操作
    安全名词
    浏览器并发连接
    acm 2057
    acm 2072
    acm 2084
    acm 2044
    acm 2043
    acm 2032
    acm 2005
  • 原文地址:https://www.cnblogs.com/mkl34367803/p/14749330.html
Copyright © 2011-2022 走看看