-
Notifications
You must be signed in to change notification settings - Fork 1
/
CooperativeScheduler.java
68 lines (65 loc) · 3.03 KB
/
CooperativeScheduler.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Vector;
public class CooperativeScheduler extends SchedulingAlgorithm{
public Results Run(int runtime, Vector processVector, Results result) {
int i = 0;
int comptime = 0;
int currentProcess = 0;
int previousProcess = 0;
int size = processVector.size();
int completed = 0;
String resultsFile = "Summary-Processes";
result.schedulingType = "Batch (Nonpreemptive)";
result.schedulingName = "First-Come First-Served";
try {
//BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile));
//OutputStream out = new FileOutputStream(resultsFile);
PrintStream out = new PrintStream(new FileOutputStream(resultsFile));
sProcess process = (sProcess) processVector.elementAt(currentProcess);
out.println("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")");
while (comptime < runtime) {
if (process.cpudone == process.cputime) {
completed++;
out.println("Process: " + currentProcess + " completed... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")");
if (completed == size) {
result.compuTime = comptime;
out.close();
return result;
}
for (i = size - 1; i >= 0; i--) {
process = (sProcess) processVector.elementAt(i);
if (process.cpudone < process.cputime) {
currentProcess = i;
}
}
process = (sProcess) processVector.elementAt(currentProcess);
out.println("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")");
}
if (process.ioblocking == process.ionext) {
out.println("Process: " + currentProcess + " I/O blocked... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")");
process.numblocked++;
process.ionext = 0;
previousProcess = currentProcess;
for (i = size - 1; i >= 0; i--) {
process = (sProcess) processVector.elementAt(i);
if (process.cpudone < process.cputime && previousProcess != i) {
currentProcess = i;
}
}
process = (sProcess) processVector.elementAt(currentProcess);
out.println("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.cpudone + ")");
}
process.cpudone++;
if (process.ioblocking > 0) {
process.ionext++;
}
comptime++;
}
out.close();
} catch (IOException e) { /* Handle exceptions */ }
result.compuTime = comptime;
return result;
}
}