From b5c5f4904dee13ff96d263f386a47774a05cb4bd Mon Sep 17 00:00:00 2001 From: Zach S-B Date: Sat, 28 Aug 2021 14:02:51 +1000 Subject: [PATCH] pre-unidispatch --- FCFS.java | 46 ++++++++++++++++++++++++---------------------- Process.java | 21 +++++++++++++-------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/FCFS.java b/FCFS.java index 0e6dcbc..8ca8937 100644 --- a/FCFS.java +++ b/FCFS.java @@ -11,18 +11,19 @@ public class FCFS { private static LinkedList processListFromFile; //Original List of processes from the the file private LinkedList waitingQueue = new LinkedList<>(); //Processes officially added to the waiting queue. - private LinkedList newProcesses = new LinkedList<>(); //Processes that have arrived after each time point. + private LinkedList newProcesses = new LinkedList<>(); //Processes that have arrived since the last check + //Constructors - public FCFS(int dispInput, LinkedList processListInput) { disp = dispInput; processListFromFile = processListInput; } - + //Check for new processes that have arrived private void checkForArrivals() { + //Check each processe from the file, and if it has arrived between timeStep and whenever we last checked, add it. for(int i = 0; i< processListFromFile.size(); i++) { if((processListFromFile.get(i).getArrive()<=timeStep) && (processListFromFile.get(i).getArrive() > timeLastChecked)) @@ -55,13 +56,18 @@ public class FCFS { { waitingQueue.add(newProcesses.get(i)); } + + //Clear the processes list so it is ready to go for the next time newProcesses.clear(); } + //Run the actual dispatch and running of programs public void runDispatch() { - System.out.println("FCFS:"); - int processesFinished = 0; + System.out.println("FCFS:"); //Currently using FCFS methodology + + int processesFinished = 0; //Used to track if we've done all the processes from the file + Process currentProcess; Process lastRunProcess = new Process("temp", 0, 0, 0); //temp process for comparing the first run @@ -72,15 +78,20 @@ public class FCFS { //As long as there is something in the queue if(waitingQueue.size()>0) { - currentProcess = findShortestProcess(); + + currentProcess = findNextProcess(); + //If the next process to run is different than the last one run, we need to run the actual dispatcher, which takes time, to change process if(!lastRunProcess.getId().equals(currentProcess.getId())) { - timeStep = timeStep+disp; + timeStep += disp; + System.out.println("T"+timeStep+": "+currentProcess.getId()); + + //Add the time waited to each of the currently waiting processes records for(int i = 0; i