-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepingTask.java
More file actions
41 lines (34 loc) · 1.04 KB
/
SleepingTask.java
File metadata and controls
41 lines (34 loc) · 1.04 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
37
38
39
40
41
package com.loon.multithreading;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* Created with IntelliJ IDEA.
* User: Loon
* Date: 13-4-8
* Time: 下午10:59
* To change this template use File | Settings | File Templates.
*/
public class SleepingTask extends LiftOff {
public void run() {
while (countDown-- > 0) {
System.out.println(stastus());
try {
// Old style
// Thread.sleep(200);
// Java SE5 style
TimeUnit.MILLISECONDS.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
System.err.println("Interrupted");
}
}
}
public static void main(String[] args) {
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i = 0; i < 5; i++) {
executorService.submit(new SleepingTask());
}
executorService.shutdown();
}
}