非Preemptibe最短的工作1

时间:2015-08-23 13:35:09

标签: java operating-system job-scheduling

我正在编写一个代码来模拟抢先最短作业第一次调度,由于某种原因,下一个函数没有被调用而变量nxt没有被更新。

    import java.util.*;
class Sjf2{
public static int next(int t,int at[],int visited[],int n){
    int i,min=at[0],minp=0;
    for(i=0;i<n;i++)
{
    if((at[i]<=t)&&(visited[i]==0)){
     if(at[i]<=min)
     {
        minp=i;
        min=at[i];
     } 
    }
}
return minp;

}
public static void main(String args[]){
    int i;
    Scanner s=new Scanner(System.in);
    System.out.println("enter the number of jobs");
    int n=s.nextInt();
    String pname[]=new String[n+1];
    int bt[]=new int[n+1];
    int tut[]=new int[n+1];
    int at[]=new int[n+1];
    int wt[]=new int [n+1];
    int visited[]=new int[n+1];
    for(i=0;i<n;i++)
    {visited[i]=0;}
    for(i=0;i<n;i++){
    System.out.println("enter name,Burst Time,Arrival Time of process "+(i+1));
    pname[i]=s.next();
    bt[i]=s.nextInt();
    at[i]=s.nextInt();
        }
int t=0,nxt=0,j;
for(j=0;j<n;j++)
{
nxt=next(t,at,visited,n);
wt[nxt]=t-at[nxt];
t=t+bt[nxt];
tut[nxt]=t+bt[nxt]-at[nxt];
visited[nxt]=1;
}
System.out.println(" non-preemtive Sjf Scheduling is as shown");
System.out.println("pname\tburst time\tarrival time\t TAT\t WT");
for(i=0;i<n;i++)
{System.out.println();
System.out.print(pname[i]+"\t");
System.out.print(bt[i]+"\t");
System.out.print(at[i]+"\t");
System.out.print(tut[i]+"\t");
System.out.print(wt[i]+"\t");


}
}
}   

输出如下所示。

enter the number of jobs
4
enter name,Burst Time,Arrival Time of process 1
p1
7
0
enter name,Burst Time,Arrival Time of process 2
p2
4
2
enter name,Burst Time,Arrival Time of process 3
p3
1
4
enter name,Burst Time,Arrival Time of process 4
p4
4
5
non-preemtive Sjf Scheduling is as shown
pname   burst time  arrival time     TAT     WT

p1  7   0   35  21  
p2  4   2   0   0   
p3  1   4   0   0   
p4  4   5   0   0   

由于nxt保持为0,因此wt [0]&amp; tat [0]正在更新。函数调用中的参数传递有什么问题吗?

0 个答案:

没有答案