-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoundRobin.java
49 lines (41 loc) · 1.53 KB
/
RoundRobin.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
import java.util.ArrayList;
import java.util.List;
public class RoundRobin extends Scheduler {
int quantum;
public RoundRobin(List<Process> processes, int quantum) {
super(processes);
this.quantum = quantum;
}
@Override
public void runScheduler() {
int timePassed = 0;
ArrayList<Process> processesList = new ArrayList<>();
for (Process process : this.processList) {
processesList.add(new Process(process.PID, process.burstTime, process.priority));
}
while (getTotalBurst(processesList) > 0) {
for (Process process : processesList) {
if (process.burstTime > quantum) {
csvFile.rows.add(new CSVRow(timePassed, process.PID, process.burstTime, 0, 0));
timePassed += quantum + 2;
process.burstTime = process.burstTime - quantum;
} else if (process.burstTime != 0) {
csvFile.rows.add(new CSVRow(timePassed, process.PID, process.burstTime, 0, timePassed + process.burstTime));
timePassed += process.burstTime + 2;
process.burstTime = 0;
}
}
}
}
@Override
public void saveCSVData() throws Exception {
csvFile.saveFile("RB-" + quantum + "-testfile.csv");
}
private int getTotalBurst(ArrayList<Process> list) {
int total = 0;
for (Process process : list) {
total += process.burstTime;
}
return total;
}
}