• 大小: 10KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: Java
  • 标签: 算法  java源码  

资源简介

用java写的进程调度算法。有时间片轮转法、先来先服务、最短运行时间优先调度算法、优先权调度算法、多级反馈队列算法。代码结构简洁,逻辑缜密。

资源截图

代码片段和文件信息

package process;
import java.util.*;
import java.lang.*;
public class Process {
    
    static   int[][]  record;
    static int time; 
    static  Vector RunProcess;
    static  Vector HasRunProcess;
    static   Vector v;
    
    public  Process(){ 
    }
   
    public static void main(String[] args) {
        record =new int[10][50];
        time=0;
        RunProcess=new Vector();
        v=new Vector();
        HasRunProcess=new Vector();
        
         PCB p1=new PCB();   
         PCB p2=new PCB(); 
         PCB p3=new PCB(); 
         
         p1.startTime=0;
         p1.needRunTime=9;
         p1.priority=0;
         p1.PID=0;
         
         v.add(p1);
         p2.PID=1;
         p2.startTime=3;
         p2.needRunTime=3;
         p2.priority=1;
         v.add(p2);
         
         p3.PID=2;
         p3.startTime=4;
         p3.needRunTime=2;
         p3.priority=2;
         v.add(p3);
         
         reset();
         System.out.println(“先到先服务调度算法“);
         FCFS();
         print();
         
         
         reset();
         System.out.println(“短作业优先调度算法“);
         SJF();
         print();
         
         reset();
         System.out.println(“高优先权优先调度算法(非抢占)“);
         FPF(); 
        print();
         
         reset();
          System.out.println(“高优先权优先调度算法(抢占)“);
         FPF_grab ();
         print();
         
         reset();
          System.out.println(“动态优先权优先调度(抢占)“);
         ActivFPF_grab();
         print(); 
         
         reset();
          System.out.println(“时间片轮转法“);
         RR();
         print();
         
         reset();
         System.out.println(“三级反馈调度算法“);
         MFB();
         print();
    }
    
   static void  FCFS(){   
       time=0;
        refreshProcessVector();
      while(RunProcess.size()>0)
      {
          PCB p=(PCB)RunProcess.get(0);
          p.startRunTime=time;
          for(int i=0;i            run(p);
            time++;
           refreshProcessVector();
        }
          p.endTime=time;
          
         HasRunProcess.add(RunProcess.get(0));
         RunProcess.remove(0);
       
      }
        
    }
   static void SJF(){
     time=0;  
      refreshProcessVector();
     SJFCompare sjfcmp= new  SJFCompare();
      while(RunProcess.size()>0)
      {
           Collections.sort(RunProcesssjfcmp);
          PCB p=(PCB)RunProcess.get(0);
          p.startRunTime=time;
          for(int i=0;i            run(p);
            time++;
           refreshProcessVector();
        }
          p.endTime=time;
          HasRunProcess.add(RunProcess.get(0));
        RunProcess.remove(0);
       
      }
          
      }
      
   static void FPF (){//非抢占 最高优先级调度算法
        time=0;
        refreshProcessVector();
       FBFCompare fbfcmp= new  FBFCompare();
      while(RunProcess.size()>0)
      {
           Collections.sort(RunProcessfbfcmp);
          PCB p=(PCB)RunProcess.get(0);
          p.sta

评论

共有 条评论