-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunner.java
More file actions
25 lines (22 loc) · 775 Bytes
/
Copy pathRunner.java
File metadata and controls
25 lines (22 loc) · 775 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
// Copyright: Ganesh Samarthyam, 2016; www.codeops.tech
import java.util.concurrent.*;
// this Runner class simulates a track runner in a 100-meter dash race. The runner waits till the
// count down timer gets to zero and then starts running
class Runner extends Thread {
private CountDownLatch timer;
public Runner(CountDownLatch cdl, String name) {
timer = cdl;
this.setName(name);
System.out.println(this.getName() + " ready and waiting for the count down to start");
start();
}
public void run() {
try {
// wait for the timer count down to reach 0
timer.await();
} catch (InterruptedException ie) {
System.err.println("interrupted -- can't start running the race");
}
System.out.println(this.getName() + " started running");
}
}