300.26模拟守护线程

来源:互联网 发布:图片管理系统源码 编辑:程序博客网 时间:2024/05/29 17:57
package 守护线程;public class T1 {public static void main(String[] args) {Thread t1 = new Thread(new Processor());t1.setDaemon(true);t1.start();for(int i = 0;i<10;i++) {try {Thread.sleep(500);}catch(Exception e) {}System.out.println(Thread.currentThread().getName());}}}class Processor implements Runnable{public void run() {int i = 0;while(true) {try {Thread.sleep(500);}catch(Exception e) {}i++;System.out.println(Thread.currentThread().getName()+"---->"+i);}}}
main
Thread-0---->1
main
Thread-0---->2
main
Thread-0---->3
main
Thread-0---->4
Thread-0---->5
main
Thread-0---->6
main
main
Thread-0---->7
main
Thread-0---->8
main
Thread-0---->9
main
Thread-0---->10