-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDaemonDemo.java
More file actions
36 lines (33 loc) · 1.21 KB
/
DaemonDemo.java
File metadata and controls
36 lines (33 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package PracticeJavaHighConcurrency.chapter2;
/**
* Created by 13 on 2017/5/4.
*/
public class DaemonDemo {
public static class DaemonT extends Thread {
public void run() {
while (true) {
System.out.println("I am alive");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/**
* thread������Ϊ�ػ��߳�,ϵͳ��ֻ�����߳�mainΪ�û��߳�,�����main�߳�����3���˳�ʱ,��������Ҳ��֮����,��������߳�thread����Ϊ�ػ��߳�,
* main�߳̽�����,t�̻߳��ͣ�Ĵ�ӡ,��ԶҲ�������.
*
* tip:��һ��JavaӦ����,ֻ���ػ��߳�ʱ,Java������ͻ��˳�.
*
* @param args
* @throws InterruptedException
*/
public static void main(String args[]) throws InterruptedException {
Thread thread = new DaemonT();
thread.setDaemon(true);
thread.start();
Thread.sleep(3000);
}
}