fpfprocessschedule.java~25~

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

JAVA~25~
96
字号
package cn.edu.cauc.crab.ossimulate;import java.util.*;/** * <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 the high responsibility first process scheduling. * * @author Crab * @version 0.1 * @see cn.edu.cauc.crab.ossimulate.ProcessSchdule */public class FPFProcessSchedule extends ProcessSchedule {    /**     * extends from ProcessSchedule a List named PCBs     */    public FPFProcessSchedule() {        super();    }    /**     * 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 hightest = (PCB)PCBs.get(0);            float tw = hightest.waitTime;            float ts = hightest.serveTime;            hightest.responsibility = (tw + ts) / ts;            Iterator p = PCBs.iterator();            while (p.hasNext()) {                PCB tempPCB = (PCB)p.next();                if (time >= tempPCB.arriveTime) {                    tempPCB.waitTime = time - tempPCB.arriveTime;                    tw = tempPCB.waitTime;                    ts = tempPCB.serveTime;                    tempPCB.responsibility = (tw + ts) / ts;                    if (tempPCB.responsibility > hightest.responsibility) {                        hightest = tempPCB;                    }                }            }            PCB pcb = hightest;            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;                ts = pcb.serveTime;                pcb.nullWorkRate =  tr / ts;                System.out.println("PID: " + pcb.pid                                   +" Responsibility:" + pcb.responsibility                                   + "Arrive: " + pcb.arriveTime                                   + " Serve: " + pcb.serveTime                                   + " Begin: " + pcb.beginTime                                   + " Finish: " + pcb.finishTime                                   + " Roll: " + pcb.rollTime                                   + " nullWorkRate: " + pcb.nullWorkRate);                PCBs.remove(pcb);            } else {                time++;            }        }    }    //for unit test    public static void main(String[] args) {        ProcessSchedule pSch = new FPFProcessSchedule();        //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 + -
显示快捷键?