文章目录
- 实验内容:
实现的算法:FCFS、SJF、HRRF
- 程序功能:
使用Java编写并调试一个模拟的进程调度程序,分别采用FCFS、SJF、HRRF调度算法进行调度,计算出开始时间、结束时间、周转时间、带权周转时间。并使用JavaGUI图形化。
- 程序流程图:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c7854349a0c710b4b205003e0a7595d6.png)
代码:
package Main;
import java.util.ArrayList;
import java.util.Vector;
import Utils.*;
import UI.*;
public class main {
public static String flag = "";
public static ArrayList<PCB> pcbArr = new ArrayList<PCB>();
public static ArrayList<PCB> rArr = new ArrayList<PCB>();
public static void main(String[] args) {
new p_UI().setVisible(true);
}
public static void start() {
if (flag == "先来先服务(FCFS)") {
rArr = FCFS.FCFS(pcbArr);
} else if (flag == "最短进程优先(SPF)") {
rArr = SPF.SPF(pcbArr);
} else if (flag == "响应比高者优先(HRN)") {
rArr = HRN.HRN(pcbArr);
}
p_UI.data.clear();
for (int i = 0; i < rArr.size(); i++) {
Vector aData = new Vector();
aData.add(rArr.get(i).id);
aData.add(rArr.get(i).name);
aData.add(rArr.get(i).priority);
aData.add(rArr.get(i).workTime);
aData.add(rArr.get(i).arriveTime);
aData.add(rArr.get(i).beginTime);
aData.add(rArr.get(i).finshTime);
rArr.get(i).setTAT(rArr.get(i).getFinshTime() - rArr.get(i).getArriveTime());
rArr.get(i).setWTAT(rArr.get(i).getTAT() / rArr.get(i).getWorkTime());
aData.add(rArr.get(i).TAT);
aData.add(rArr.get(i).WTAT);
p_UI.data.add(aData);
}
p_UI.dtm.setDataVector(p_UI.data, p_UI.colName);
p_UI.table.setModel(p_UI.dtm);
}
public static void revoke() {
p_UI.tTAT.setText("");
p_UI.tWTAT.setText("");
p_UI.data.clear();
for (int i = 0; i < pcbArr.size(); i++) {
Vector aData = new Vector();
aData.add(pcbArr.get(i).id);
aData.add(pcbArr.get(i).name);
aData.add(pcbArr.get(i).priority);
aData.add(pcbArr.get(i).workTime);
aData.add(pcbArr.get(i).arriveTime);
p_UI.data.add(aData);
}
p_UI.dtm.setDataVector(p_UI.data, p_UI.colName);
p_UI.table.setModel(p_UI.dtm);
}
}
package Main;
public class PCB {
public int id;
public String name;
public int priority;
public double workTime;
public double arriveTime;
public double beginTime;
public double finshTime;
public double TAT;
public double WTAT;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public double getWorkTime() {
return workTime;
}
public void setWorkTime(double workTime) {
this.workTime = workTime;
}
public double getArriveTime() {
return arriveTime;
}
public void setArriveTime(double arriveTime) {
this.arriveTime = arriveTime;
}
public double getBeginTime() {
return beginTime;
}
public void setBeginTime(double beginTime) {
this.beginTime = beginTime;
}
public double getFinshTime() {
return finshTime;
}
public void setFinshTime(double finshTime) {
this.finshTime = finshTime;
}
public double getTAT() {
return TAT;
}
public void