-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemSimulator.java
51 lines (42 loc) · 1.09 KB
/
SystemSimulator.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Scheduler;
import java.util.ArrayList;
class SystemSimulator extends Thread {
private Scheduler myScheduler = new Scheduler();
private boolean noMoreJobsToSubmit = false;
private boolean jobCurrentlyRunning = false;
private long startTime;
ArrayList<Job> completedJobList;
public SystemSimulator() {
}
public void run() {
startTime = System.currentTimeMillis();
while (!myScheduler.isReadyQEmpty() || !noMoreJobsToSubmit) {
try {
sleep(10);
} catch (InterruptedException e) {
myScheduler.makeRun();
jobCurrentlyRunning = true;
}
}
while (jobCurrentlyRunning) {
try {
sleep(10);
} catch (InterruptedException e) {
}
}
myScheduler.printGannt();
}
public long relativeTime() {
return System.currentTimeMillis() - startTime;
}
public void noMoreJobsToSubmit() {
noMoreJobsToSubmit = true;
}
void AddNewProcess(Job createJob) {
myScheduler.add(createJob);
}
void Exit() {
myScheduler.addCompletedJob((Job) Thread.currentThread());
jobCurrentlyRunning = false;
}
}