欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java实现操作系统的短进程作业调度示例分享

程序员文章站 2024-02-24 15:35:04
复制代码 代码如下:package com; import java.util.arrays; public class sjf {  pu...

复制代码 代码如下:

package com;

import java.util.arrays;
 public class sjf {

  public static void main(string[] args) {
   sjf sjf=new sjf();
   sjf.fun1();
  }

  int starttime;
  int arrivetime;
  int finishtime;
  int zhouzhuan;
  

  public void fun1(){

   int a[]={1,3,2};
   int c[]=new int[3];
   for (int i = 0; i < 3; i++) {
    c[i]=a[i];
   }
   arrays.sort(c);
   finishtime=a[0];
   int[]d={0,3,3};
   int zhouzhuan=finishtime-arrivetime;
   float weightzhouzhuan=(float)zhouzhuan/a[0];//位权周转时间为周转时间h
   system.out.println("开始时间"+starttime+"\t"+"到达时间"
     +arrivetime+"\t"+"完成时间"+finishtime+"\t"+"周转时间"+zhouzhuan+"\t"+"服务时间"+a[0]+"\t"+"带权周转时间"+weightzhouzhuan);

   for (int i = 1; i < 3; i++) {
    arrivetime=d[i];
    if(finishtime>=arrivetime){
     starttime=finishtime;
     finishtime+=c[i];
     zhouzhuan=finishtime-arrivetime;
     weightzhouzhuan=(float)zhouzhuan/c[i];
     system.out.println("开始时间"+starttime+"\t"+"到达时间"
       +arrivetime+"\t"+"完成时间"+finishtime+"\t"+"周转时间"+zhouzhuan+"\t"+"服务时间"+c[i]+"\t"+"带权周转时间"+weightzhouzhuan);
    }else{

     arrays.sort(c);
     starttime=arrivetime;
     finishtime=starttime+c[i];
     zhouzhuan=finishtime-arrivetime;
     weightzhouzhuan=(float)zhouzhuan/c[i];
     system.out.println("开始时间"+starttime+"\t"+"到达时间"
       +arrivetime+"\t"+"完成时间"+finishtime+"\t"+"周转时间"+zhouzhuan+"\t"+"服务时间"+c[i]+"\t"+"带权周转时间"+weightzhouzhuan);

    }

    
   }
  }

 }