-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMLFQScheduler.java
More file actions
87 lines (77 loc) · 3.56 KB
/
MLFQScheduler.java
File metadata and controls
87 lines (77 loc) · 3.56 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
public class MLFQScheduler {
private Queue timeline;
private Queue inputQueue;
private Queue resultQueue;
private Queue queueA;
private Queue queueB;
private Queue queueC;
private int[] quantums;
private int finalMode;
private Logger logger;
public MLFQScheduler(Queue timeline, int quantumA, int quantumB, int finalMode) {
this.initializeTimeline(timeline);
this.initializeQueues();
this.quantums = new int[]{quantumA, quantumB};
this.logger = new Logger();
this.finalMode = finalMode;
}
public void run() {
System.out.println("[TIMELINE]");
this.timeline.print();
System.out.println("");
while (true) {
while (!inputQueue.isEmpty() && inputQueue.front().getArrivalTime() <= logger.getTime()) {
inputQueue.front().setEndTime(logger.getTime());
queueA.enqueue(inputQueue.dequeue());
}
if (!queueA.isEmpty()) {
queueA.RR(this.quantums[0], this.logger);
}
else if (!queueB.isEmpty()) {
queueB.RR(this.quantums[1], this.logger);
}
else if (!queueC.isEmpty()) {
switch (this.finalMode) {
case 1:
queueC.FCFS(this.logger);
break;
case 2:
queueC.SJF(this.logger);
break;
case 3:
queueC.NPP(this.logger);
break;
default:
break;
}
} else {
this.logger.incrementTime(1);
}
if (this.logger.getCount() == this.timeline.size())
break;
}
resultQueue.calculateResults();
System.out.println("[RESULTS]");
resultQueue.print();
System.out.println("\n[GANTT CHART]");
this.logger.printLogs();
}
public void initializeTimeline(Queue timeline) {
this.timeline = new Queue(timeline, "TIMELINE");
this.timeline.sort("AT");
}
public void initializeQueues() {
this.inputQueue = new Queue(this.timeline, "input");
this.resultQueue = new Queue("result");
this.queueA = new Queue("queueA");
this.queueB = new Queue("queueB");
this.queueC = new Queue("queueC");
this.inputQueue.setNextQueue(this.queueA);
this.queueA.setNextQueue(this.queueB);
this.queueB.setNextQueue(this.queueC);
this.queueC.setNextQueue(this.resultQueue);
this.queueA.setResultQueue(this.resultQueue);
this.queueB.setResultQueue(this.resultQueue);
this.queueC.setResultQueue(this.resultQueue);
}
}