-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.java
More file actions
81 lines (69 loc) · 1.74 KB
/
FCFS.java
File metadata and controls
81 lines (69 loc) · 1.74 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
/** -----------------------------------------------------------------------
FCFS.java
@author William Clift
Operating Systems
Ursinus College
Project 2 - Scheduling Schemes
14 April 2020
Compile Instructions:
Compile: javac FCFS.java
------------------------------------------------------------------- **/
import java.util.*;
public class FCFS extends Scheme{
public String scheme = "FCFS";
public String fileName;
public CircularLL incoming;
public CircularLL toSchedule;
public CircularLL processed;
/**
* First Come, First Served Algorithm
*
*/
public FCFS(CircularLL incoming, String scheme){
super(incoming, scheme);
this.incoming = incoming;
this.toSchedule = new CircularLL();
this.processed = new CircularLL();
checkArrival();
}
/**
* Runs the Algorithm
*
*/
public void run(){
System.out.println("============================================================");
boolean done = false; // Sentinal Value
while(!done){
if(incoming.getSize() > 0){
checkArrival();
}
if(toSchedule.getSize()>0){ // If there are processes left
PCB current = toSchedule.pop();
PCB result = cpuProcess(current, current.burst_time, toSchedule, incoming); // Run the next Process in line
processed.push(result);
}else{
cpuTick();
}
if(incoming.getSize() < 1 && toSchedule.getSize()<1){
done = true;
}
}
printEndMetrics(processed);
}
/**
* Check if any processes have arrived.
*
*/
private void checkArrival(){
PCB current = incoming.head;
for(int i = 0; i < incoming.getSize(); i++){
current = incoming.head;
if(current.arrival_time == cpuTime){
PCB in = incoming.pop();
toSchedule.push(in);
}else{
incoming.work();
}
}
}
}