-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOSThread.java
28 lines (25 loc) · 1.02 KB
/
OSThread.java
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
///////////////////
// OSThread: Class that holds all functions for Thread actions and processes
///////////////////
class OSThread implements Runnable {
private Thread t; //the thread object itself
private Console console = new Console(); //make sure we include console for logging
private Clock clock = new Clock(); //make sure we include clock for simulating wait times
private long countTime; //used to hold the number of ms we should wait
//start - the publically accessible start function that will call run()
public void start(long inputCountTime) {
countTime = inputCountTime;
if (t == null) {
t = new Thread(this);
t.start();
}
}
//run - the threaded function that will run in parallel with the rest of the program
public void run() {
clock.timer(countTime); //wait using the clock timer
}
//isRunning - returns whether or not the thread is currently running
public boolean isRunning() {
return t.isAlive();
}
}