我正在尝试用java创建一个进程调度程序。我有一个示例进程类和一个调度程序类,我在其中执行调度逻辑。我在先到先服务器 (FCFS) 方法的第一行遇到错误。
Queue.add(Arriving.get(0));
线程“main”中的异常 java.lang.IndexOutOfBoundsException:索引:0,大小:0 在 java.util.ArrayList.rangeCheck(未知来源) 在 java.util.ArrayList.get(未知来源)
public class Scheduler {
// I use two lists to keep track of the processes that haven't arrived and the processes in the cpu queue
ArrayList<Process> Arriving;
ArrayList<Process> Queue;
Process runningProcess;
int currentTime;
// new process boolean used to check if a process was added to the cpu queue
boolean newProcess;
public Scheduler(ArrayList<Process> Queue){
Arriving = new ArrayList<Process>();
Queue = new ArrayList<Process>();
for (int i = 0; i<Queue.size(); i++) {
Arriving.add(Queue.get(i));
}
Sort();
currentTime = 0;
}
public void FCFS(){
Queue.add(Arriving.get(0));
Arriving.remove(0);
runningProcess = Queue.get(0);
while(runningProcess.getRemainingTime() != 0){
if (runningProcess.getRemainingTime()==0){
Queue.remove(runningProcess);
runningProcess = Queue.get(0);
}
while (Arriving.get(0) != null){
for(Process process:Arriving){
if (process.getArrivalTime()==currentTime){
Queue.add(Arriving.get(0));
Arriving.remove(0);
}
else
break;
}
runningProcess.running();
for(int i = 1; i<Queue.size(); i++)
Queue.get(i).waiting();
}
System.out.println(Queue.size() + " processes waiting.");
currentTime++;
}
}
慕斯王
慕村225694
慕运维8079593
相关分类