-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaemonFromFactory.java
More file actions
41 lines (30 loc) · 867 Bytes
/
DaemonFromFactory.java
File metadata and controls
41 lines (30 loc) · 867 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
40
41
package Thread.DemoThread;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class DaemonFromFactory implements Runnable{
@Override
public void run() {
try {
while(true){
TimeUnit.MILLISECONDS.sleep(100);
System.out.println(Thread.currentThread());
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
ExecutorService service=Executors.newCachedThreadPool(new DaemonThreadFactory());
for(int i=0;i<5;i++)
service.execute(new DaemonFromFactory());
System.out.println("all daemon started");
try {
TimeUnit.MILLISECONDS.sleep(99);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}