-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLiftOff.java
More file actions
38 lines (28 loc) · 705 Bytes
/
LiftOff.java
File metadata and controls
38 lines (28 loc) · 705 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
package concurrency;
import java.io.*;
import java.util.*;
/**
* RUN:
* javac concurrency/LiftOff.java && java concurrency.LiftOff
*
* OUTPUT:
*
*/
public class LiftOff implements Runnable {
protected int countDown = 10;
private static int taskCount = 0;
private final int id = taskCount++;
public LiftOff() {}
public LiftOff(int countDown) {
this.countDown = countDown;
}
public String status() {
return "#" + id + "("+(countDown > 0 ? countDown : "Liftoff!") + "), ";
}
public void run() {
while (countDown-- > 0) {
System.out.print(status());
Thread.yield();
}
}
}