I am curious how to implement a FIFO (first in, first out) algorithm in Java. I have 3 classes already created, but have to implement the scheduling algorithms for FIFO and SJF (Shortest Job First).
For the simulator class, we have the following variables:
private CPU cpu1;
private ArrayList<Process> ready;
private ArrayList<Process> finished;
private int time;
Then the method is:
public Process select(ArrayList<Process> ready){
if(SCHEDULING_ALGORITHM.equals("FIFO"))
{
//add code here
}
else if(SCHEDULING_ALGORITHM.equals("SJF"))
//add code here
}
other methods are:
public void addProcess(String name, int start, int length)
{
Process temp = new Process(name, start, length);
ready.add(temp);
}
There are two other classes Process and CPU. Process holds any information about a single process that should be stored there.