?? fcfsprocessschedule.java~31~
字號:
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"); } } else { time++; } } } 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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -