Java静态优先数调度算法.doc_第1页
Java静态优先数调度算法.doc_第2页
Java静态优先数调度算法.doc_第3页
Java静态优先数调度算法.doc_第4页
Java静态优先数调度算法.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

CommProcess.java文件public class CommProcess private int ID; /进程名 private int pri; /优先数 private int needtime; /进程到完成还要的时间,单位s,小于等于10s private char state = R; /进程状态 public CommProcess(int id, int pri, int needtime) super(); ID = id; this.pri = pri; this.needtime = needtime; public synchronized void run() try if (ReadCmand = 1) state = E; needtime-; if (needtime = 0) state = F; Test.count+; catch (Exception e) e.printStackTrace(); public int getID() return ID; public void setID(int id) ID = id; public int getNeedtime() return needtime; public int getPri() return pri; public char getState() return state; public void setState(char state) this.state = state; ReadCommand.java文件import java.io.InputStream;import java.util.ArrayList;import java.util.Scanner;public class ReadCommand public static int command = 0;/1-继续执行 2-阻塞 3-唤醒 public static void getCommand() print(); InputStream is = System.in;/*输入流*/ Scanner scan = new Scanner(is);/*从控制台输入*/ int count = 1; boolean taget = false; while (true) if (Test.count = 3) return; ArrayList commands = new ArrayList(); commands.add(1); commands.add(2); commands.add(3); String comString = ; while (!commands.contains(comString = scan.next()/*判断是否有数据*/ System.out.println(请输入整数1、2、3); command = Integer.parseInt(comString); if (command = 1) int size = Test.list.size(); CommProcess runCommProcess = Test.map.get(Test.list.get(size - count); while (runCommProcess.getNeedtime() = 0 | runCommProcess.getState() = W | runCommProcess.getState() = F) count+; int temp = size - count; if (temp 0) System.out.println(没有可选的线程); taget = true; count = 1; break; runCommProcess= Test.map.get(Test.list.get(temp); if (taget) taget = false; continue; runCommProcess.run(); if (runCommProcess.getNeedtime() size) count = 1; if (command = 2) count = 1; int size = Test.list.size(); for (int i = 0; i 0 & temp.getState() = E) temp.setState(W); print(); if (command = 3) boolean target = false; int size = Test.list.size(); for (int i = 0; i = 0; i-) CommProcess temp = Test.map.get(Test.list.get(i); if (temp.getState() = E) temp.setState(R); else if (temp.getNeedtime() 0 & temp.getState() = W) /不能直接设置,需要比较权重 if (falg) falg = false; temp.setState(E); else temp.setState(R); print(); public static void print() /打印各进程程状态 for (int i = 0; i Test.list.size(); i+) CommProcess temp = Test.map.get(Test.list.get(i); System.out.println( P+temp.getID() + priority= + temp.getPri() + needtime= + temp.getNeedtime() + state= + temp.getState(); System.out.println(-); System.out.println( 1-继续执行 2-阻塞 3-唤醒); Test.java文件import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Random;public class Test public static int count = 0; public static Map map = new HashMap(); public static List list = new ArrayList(); public static void main(String args) System.out.println(); System.out.println(*静态优先数调度算法演示*); Random random = new Random(); int priorityP1 = 15; int needTimeP1 = random.nextInt(10)+1%5; CommProcess commProcessP1 = new CommProcess(1, priorityP1, needTimeP1);/*实例化进程P1*/ map.put(priorityP1, commProcessP1);/*插入元素*/ list.add(priorityP1); int priorityP2 = 10; int needTimeP2 = random.nextInt(10)+1; CommProcess commProcessP2 = new CommProcess(2, priorityP2, needTimeP2);/*实例化进程P2*/ map.put(priorityP2, commProcessP2); list.add(priorityP2); int priorityP3 = 5; int needTimeP3 = random.nextInt(10)+1; CommProcess commProcessP3 = new CommProcess(3, priorityP3, needTimeP3);/*实例

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论