rup pac ++ exception pro 打印 string process cat
在java 中有2种线程,1种是守护线程,1种是非守护线程
守护线程是一种特殊的线程,当线程中不存在非守护线程时,则守护线程自动销毁,典型的守护线程就是垃圾回收线程。
测试如下
- package com.cky.daemon;
- /**
- * Created by edison on 2017/12/3.
- */
- public class MyThreads extends Thread {
- private int i = 0;
- @Override public void run() {
- super.run();
- try {
- while (true) {
- i++;
- System.out.println("i=" + i);
- Thread.sleep(1000);
- }
- } catch(InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- package com.cky.daemon;
- /**
- * Created by edison on 2017/12/3.
- */
- public class Tesst11 {
- public static void main(String[] args) {
- try {
- MyThreads myThreads = new MyThreads();
- //设置其为守护线程,默认为false,非守护线程
- myThreads.setDaemon(true);
- myThreads.start();
- Thread.sleep(5000);
- System.out.println("我离开thread对象,再也不打印了");
- } catch(InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- i=1
- i=2
- i=3
- i=4
- i=5
- i=6
- 我离开thread对象,再也不打印了
- Process finished with exit code 0
1.11守护线程
rup pac ++ exception pro 打印 string process cat
原文:http://www.cnblogs.com/edison20161121/p/7954813.html
来源: http://www.bubuko.com/infodetail-2416065.html