⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fpfprocessschedule.java~23~

📁 进程调度和存储管理模拟
💻 JAVA~23~
字号:
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;            PCBs.remove(pcb);            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);            }        }    }    //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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -