?? fpfprocessschedule.java~21~
字號:
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("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 + -