-
Notifications
You must be signed in to change notification settings - Fork 0
/
SJF.java
36 lines (30 loc) · 1.07 KB
/
SJF.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
import java.util.ArrayList;
import java.util.List;
public class SJF extends Scheduler {
public SJF(List<Process> processes) {
super(processes);
}
@Override
public void runScheduler() {
int timePassed = 0;
ArrayList<Process> processesList = new ArrayList<>();
for (Process process : this.processList) {
processesList.add(process);
}
while (processesList.size() > 0) {
Process shortestProcess = processesList.get(0);
for (Process process : processesList) {
if (process.burstTime < shortestProcess.burstTime) {
shortestProcess = process;
}
}
csvFile.rows.add(new CSVRow(timePassed, shortestProcess.PID, shortestProcess.burstTime, 0, timePassed + shortestProcess.burstTime));
timePassed += shortestProcess.burstTime + 2;
processesList.remove(shortestProcess);
}
}
@Override
public void saveCSVData() throws Exception {
csvFile.saveFile("SJF-testfile.csv");
}
}