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

📄 tfprocessschedule.java~43~

📁 进程调度和存储管理模拟
💻 JAVA~43~
字号:
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 time fragment scheduling. * * @author Crab * @version 0.1 * @see cn.edu.cauc.crab.ossimulate.ProcessSchdule */public class TFProcessSchedule extends ProcessSchedule {    JTextArea out;    private int timeFragment;    /**     * extend from ProcessSchdule a List PCBs.     * @param timeFragment the time fragment to schedule the process.     */    public TFProcessSchedule(int timeFragment) {        super();        this.timeFragment = timeFragment;    }    public TFProcessSchedule(int timeFragment, JTextArea out) {        super();        this.timeFragment = timeFragment;        this.out = out;    }    /**     * extends from ProcessSchedule     * After addProcess() is calling,     * use to start scheduling.     */    public void start() {        int time = 0;        while (!PCBs.isEmpty()) {            Iterator p = PCBs.iterator();            while (p.hasNext()) {                PCB tempPCB = (PCB)p.next();                if (tempPCB.arriveTime <= time && tempPCB.leftTime != 0) {                    if (tempPCB.leftTime == tempPCB.serveTime) {                        tempPCB.beginTime = time;                    }                    if (tempPCB.leftTime >= timeFragment) {                        tempPCB.leftTime -= timeFragment;                        time += timeFragment;                        if (tempPCB.leftTime == 0) {                            tempPCB.finishTime = time;                        }                    } else {                        time += tempPCB.leftTime;                        tempPCB.finishTime = time;                        tempPCB.leftTime = 0;                    }                    if (tempPCB.leftTime == 0) {                        tempPCB.rollTime = tempPCB.finishTime - tempPCB.arriveTime;                            // use tr ts to rise the precesion.                            float tr = tempPCB.rollTime;                            float ts = tempPCB.serveTime;                            tempPCB.nullWorkRate =  tr / ts;                            if (out == null) {                                System.out.println("PID: " + tempPCB.pid                                        +" Arrive: " + tempPCB.arriveTime                                        + " Serve: " + tempPCB.serveTime                                        + " Begin: " + tempPCB.beginTime                                        + " Finish: " + tempPCB.finishTime                                        + " Roll: " + tempPCB.rollTime                                        + " nullWorkRate: " + tempPCB.nullWorkRate);                            } else {                                out.append("PID: " + tempPCB.pid                                        +" Arrive: " + tempPCB.arriveTime                                        + " Serve: " + tempPCB.serveTime                                        + " Begin: " + tempPCB.beginTime                                        + " Finish: " + tempPCB.finishTime                                        + " Roll: " + tempPCB.rollTime                                        + " nullWorkRate: " + tempPCB.nullWorkRate                                        + "\n");                            }                            p.remove();//remove the finish process.                    } else {                        if (out == null) {                            System.out.println("@PID: " + tempPCB.pid                                    + " LeftTime: " + tempPCB.leftTime);                        } else {                            out.append("@PID: " + tempPCB.pid                                    + " LeftTime: " + tempPCB.leftTime                                    + "\n");                        }                    }                } else {                    //time ++;                }            }        }    }    public static void main(String[] args) {        ProcessSchedule pSch = new TFProcessSchedule(3);        //pSch.addProcess(new Process(10), 0);        pSch.addProcess(new Process(10), 1);        pSch.addProcess(new Process(10), 2);        pSch.addProcess(new Process(10), 3);        pSch.addProcess(new Process(10), 4);        pSch.start();    }}

⌨️ 快捷键说明

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