zoukankan      html  css  js  c++  java
  • setDaemon的简单使用

    //copyright©liupengcheng
    //http://www.cnblogs.com/liupengcheng

    /**
    * Created by Administrator on 2014/10/23.
    *
    *
    setDaemon
    public final void setDaemon(boolean on)将该线程标记为守护线程或用户线程。当正在运行的线程都是守护线程时,Java 虚拟机退出。
    该方法必须在启动线程前调用。

    该方法首先调用该线程的 checkAccess 方法,且不带任何参数。这可能抛出 SecurityException(在当前线程中)。

    参数:
    on - 如果为 true,则将该线程标记为守护线程。
    */

    //copyright©liupengcheng
    //http://www.cnblogs.com/liupengcheng

    public class ThreadDemo3 {
        public static void main(String [] args){
            TestThread1 tt = new TestThread1();
            Thread t = new Thread(tt);
            t.setDaemon(true);
            t.start();
        }
    }

    //copyright©liupengcheng
    //http://www.cnblogs.com/liupengcheng


    class TestThread1 implements Runnable{
        public void run()
        {
            while (true)
            {
                System.out.println(Thread.currentThread().getName()+"is running");
            }
        }

    }

    //copyright©liupengcheng
    //http://www.cnblogs.com/liupengcheng

    //输出结果为空,因为所有线程都为守护线程,Java 虚拟机退出

  • 相关阅读:
    Release COM Objects in AE
    图像相关系数
    Geoprocessor edit the featureclasses in memmory
    NetLogo AStar path finding
    IDL+C#三种调用方式
    Dictionary is not like a array
    C# DataGridView 禁止列排序
    工作总结
    (转)常见数据库设计(1)——字典数据
    碎碎念(3)
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/4045886.html
Copyright © 2011-2022 走看看