【发布时间】:2017-04-18 16:03:45
【问题描述】:
我正在尝试用 java 编写一个 CPU 调度模拟器。进程按顺序进行处理,使得应首先处理具有最少突发时间(处理时间)的进程。在开始之前,我在 ArrayList 中输入所有进程,指定名称、突发时间和到达时间。如果所有进程同时进入,则代码在逻辑上运行良好。
问题是进程有不同的到达时间。如何编辑代码以考虑此到达时间。
我只需要编辑让我以最少突发时间(相对于到达时间)获得流程的代码部分
public Process removeSJ(){ // removes & returns the process with the min. burst time
int minBurstTime = processes.get(0).getBurstTime(); // processes is ArrayList of Processe objects
int minIndex = 0;
for (int i=1 ; i<processes.size(); i++){
int curBurstTime = processes.get(i).getBurstTime();
if ( (curBurstTime < minBurstTime)){
minBurstTime = curBurstTime;
minIndex = i;
}
}
numberOfProcesses--;
return (processes.remove(minIndex));}
样本输出
The processor schedules process : P2
arrival time = 8 , burst time = 1 , waiting Time = 0
Turnaround time = 1
The processor schedules process : P3
arrival time = 5 , burst time = 3 , waiting Time = 1
Turnaround time = 4
The processor schedules process : P1
arrival time = 1 , burst time = 9 , waiting Time = 4
Turnaround time = 13
****** Average Turnaround Time = 6 ******
【问题讨论】:
标签: java algorithm operating-system