-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriorityComparator.java
47 lines (43 loc) · 2.55 KB
/
PriorityComparator.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
package ProcessScheduler;
import java.util.*;
class PriorityComparator implements Comparator<Process>{
private static int weightThreshold = 11; // cutoff burst/weight level to move process up the priority queue
private static int weightMoves = 0; // number of processes moved due to the above circumstance
/*************************************************************************
* comparator method, used to sort each priority queue into order based on
* their burst. As a solution to the starvation of longer processes it
* also moves processes higher up the queue if their burst is above a
* certain level.
*************************************************************************/
public int compare(Process pA, Process pB) {
if(pA.getBurst() > pB.getBurst()){ // if old
return 1; // move process up queue
}else if(pB.getWeight() > weightThreshold){ // if the burst of the process is over the cutoff then move up queue
System.out.println("Process "+pB.getID()+" moved up queue due to high burst of "+ pB.getBurst());
weightMoves++; // increment weightMoves
return 1; // move process up queue
}else if(pA.getBurst() < pB.getBurst()){
return -1; // move process down queue
}
return 0;
}
/**************************************************************************
* method to return the number of processes moved due to high weight/burst.
**************************************************************************/
public static int getWeightMoves(){
return weightMoves;
}
/**************************************************************************
* method to reset the number of processes moved due to high weight/burst.
**************************************************************************/
public static void resetWeightMoves(){
weightMoves = 0;
}
/**************************************************************************
* method to set the burst cutoff level that results in processes being
* moved due to high weight/burst.
**************************************************************************/
public static void setWeight(int WT){
weightThreshold = WT;
}
}