fcfsprocessschedule.java~35~

来自「进程调度和存储管理模拟」· JAVA~35~ 代码 · 共 92 行

JAVA~35~
92
字号
package cn.edu.cauc.crab.ossimulate;import java.util.*;import javax.swing.*;/** * <p>Title: OS simulate</p> * <p>Description: This is my home work.</p> * <p>Copyright: Copyleft (c) 2004</p> * <p>Company: CAUC</p> * @author Crab * @version 0.1 *//** * To simulate first come first serve process scheduling. * * @author Crab * @version 0.1 * @see cn.edu.cauc.crab.ossimulate.ProcessSchdule */public class FCFSProcessSchedule extends ProcessSchedule {    JTextArea out;    /**     * extends from ProcessSchedule a List named PCBs     */    public FCFSProcessSchedule() {        super();    }    public FCFSProcessSchedule(JTextArea out) {        super();        this.out = out;    }    /**     * extends from ProcessSchedule     * After addProcess() is calling,     * use to start scheduling.     */    public void start() {        int time = 0;//set the beging time        while (!PCBs.isEmpty()) {            PCB pcb = (PCB)PCBs.get(0);//get the fist come process            PCBs.remove(0);// because the process will finish at once, so remove it.            if (time >= pcb.arriveTime) {// the process must run >= arrive time                pcb.beginTime = time;                time += pcb.serveTime;                pcb.finishTime = time;                pcb.rollTime = pcb.finishTime - pcb.arriveTime;                // use tr ts to rise the precesion.                float tr = pcb.rollTime;                float ts = pcb.serveTime;                pcb.nullWorkRate =  tr / ts;                if (out == null) {                    System.out.println("PID: " + pcb.pid                                       +" Arrive: " + pcb.arriveTime                                       + " Serve: " + pcb.serveTime                                       + " Begin: " + pcb.beginTime                                       + " Finish: " + pcb.finishTime                                       + " Roll: " + pcb.rollTime                                       + " nullWorkRate: " + pcb.nullWorkRate);                } else {                    out.append("PID: " + pcb.pid                                       +" Arrive: " + pcb.arriveTime                                       + " Serve: " + pcb.serveTime                                       + " Begin: " + pcb.beginTime                                       + " Finish: " + pcb.finishTime                                       + " Roll: " + pcb.rollTime                                       + " nullWorkRate: " + pcb.nullWorkRate                                       + "\n");                }            }            time = pcb.arriveTime;        }    }    public static void main(String[] args) {        ProcessSchedule pSch = new FCFSProcessSchedule();        //pSch.addProcess(new Process(4), 0);        pSch.addProcess(new Process(3), 1);        pSch.addProcess(new Process(5), 2);        pSch.addProcess(new Process(2), 3);        pSch.addProcess(new Process(4), 4);        pSch.start();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?