-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimpleDaemons.java
More file actions
39 lines (32 loc) · 934 Bytes
/
SimpleDaemons.java
File metadata and controls
39 lines (32 loc) · 934 Bytes
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
37
38
39
package concurrency;
import java.io.*;
import java.util.concurrent.*;
import java.util.*;
/**
* RUN:
* javac concurrency/SimpleDaemons.java && java concurrency.SimpleDaemons
*
* OUTPUT:
*
*/
public class SimpleDaemons implements Runnable {
public void run() {
try {
while (true) {
TimeUnit.MILLISECONDS.sleep(100);
System.out.println(Thread.currentThread() + " " + this);
}
} catch(InterruptedException e) {
System.out.println("sleep() interrupted");
}
}
public static void main(String[] args) throws Exception {
for (int i = 0; i < 10; i++) {
Thread daemon = new Thread(new SimpleDaemons());
daemon.setDaemon(true);
daemon.start();
}
System.out.println("All daemons are running");
TimeUnit.MILLISECONDS.sleep(200);
}
}