java中的意外程序终止

java中的意外程序终止,java,Java,在这个内部主方法中,当我将arrivalTime[0]输入为0时,工作正常,但当我键入的输入值大于0时,它会异常失败 Thsi程序正在实现RR调度,其中我创建了一个私有静态void findWaitingTime方法(int n,int[]bTime,int[]arrivalTime,int quantum,int[]wTime) 此函数将获取进程数、突发时间、到达时间以及分配给每个GeneralProcesss的量子时隙 package Others; import java

在这个内部主方法中,当我将arrivalTime[0]输入为0时,工作正常,但当我键入的输入值大于0时,它会异常失败

Thsi程序正在实现RR调度,其中我创建了一个私有静态void findWaitingTime方法(int n,int[]bTime,int[]arrivalTime,int quantum,int[]wTime)

此函数将获取进程数、突发时间、到达时间以及分配给每个GeneralProcesss的量子时隙

    package Others;

    import java.io.BufferedReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    import java.io.InputStreamReader;
    import java.io.IOException;

    /**
     * RR scheduling implememtation with the process queue as a list
     *
     * @author Badal
     * @data 2 june 2020
     */



    public class RR_Scheduling {

        /**
this function will take number of processes , burst time, arrival time, and the quantum slot alotted to each generall processs. */

        private static void findWaitingTime(int n, int[] bTime, int[] arrivalTime ,int quantum, int[] wTime){
            // array to store remaing time of respective process
            int[] rem_bt = new int[n];

            int cpu_time = 0;

            // initially it will be equal to the burst time of all processes respectively
            for( int i = 0; i < n; i++ ) rem_bt[i] = bTime[i];



            // get the processes queue
            List<Integer> pQueue = new ArrayList<Integer>();

            // get the processes by thier arrival time
            for( int i = 0; i < n; i++ ){
                if( arrivalTime[i] == cpu_time){
                    pQueue.add(i);
                }
            }



            // executed process
            int executedProcess = 0;
            while(executedProcess != n){

                // process all pQueue processes
                for( int p = 0; p < pQueue.size(); p++){

                    // if not done 
                    if( rem_bt[ pQueue.get(p) ] > 0 ){

                        // partail execution
                        if( rem_bt[pQueue.get(p)] > quantum){

                            // collect all the processes that arrive under the execution 
                            for( int i = 0; i < n; i++){
                                if(  arrivalTime[i] > cpu_time && arrivalTime[i] < cpu_time + quantum ){
                                    // add to pQueue
                                    pQueue.add(i);
                                }
                            }

                            // update cpu_time
                            cpu_time += quantum;

                            // update rem_bt time
                            rem_bt[pQueue.get(p)] -= quantum;
                        }
                        else{



                            // collect all the processes that arrive under the execution 
                            for( int i = 0; i < n; i++){
                                if(  arrivalTime[i] > cpu_time && arrivalTime[i] < cpu_time + rem_bt[pQueue.get(p)]){
                                    // add to pQueue
                                    pQueue.add(i);
                                }
                            }

                            // udpate cpu_time
                            cpu_time += rem_bt[pQueue.get(p)];

                            // completely executed
                            rem_bt[pQueue.get(p)] = 0;

                            // fetch completion time and waiting time
                            int completionTime = cpu_time - arrivalTime[pQueue.get(p)];
                            wTime[pQueue.get(p)] = completionTime - bTime[pQueue.get(p)];

                            //update execute process
                            executedProcess++;

                        }
                    }



                    // get the processes by thier arrival time
                    for( int i = 0; i < n; i++ ){
                        if( arrivalTime[i] == cpu_time){
                            pQueue.add(i);
                        }
                    }
                }

            }
        }


        // take number of processes via command line
        public static void main(String[] args) throws IOException{
            BufferedReader br = new BufferedReader( new InputStreamReader( System.in ));

            int processes = Integer.parseInt(br.readLine());
            int[] arrivalTime = new int[processes];
            int[] burstTime = new int[processes];
            for( int i = 0; i < processes; i++ ){
                arrivalTime[i] = Integer.parseInt(br.readLine());
                burstTime[i] = Integer.parseInt(br.readLine());
            }

            int[] waitingTime = new int[processes];
            int quantum = Integer.parseInt(br.readLine());

            findWaitingTime(processes, burstTime, arrivalTime, quantum, waitingTime);// ??? if arrivalTime[0] >= 1 then it terminating the program.. but working if arrivalTime[0] is 0

            for( int i = 0; i < processes; i++){
                System.out.println("Waiting time : " + waitingTime[i]);
            }


        }

    }
打包其他;
导入java.io.BufferedReader;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Scanner;
导入java.io.InputStreamReader;
导入java.io.IOException;
/**
*以进程队列为列表的RR调度实现
*
*@作者巴达尔
*@data 2020年6月2日
*/
公共类RR_调度{
/**
此函数将获取进程数、突发时间、到达时间以及分配给每个GeneralProcesss的量子时隙*/
私有静态void findWaitingTime(int n,int[]bTime,int[]arrivalTime,int quantum,int[]wTime){
//用于存储各个进程的剩余时间的数组
int[]rem_bt=新的int[n];
int cpu_时间=0;
//最初,它将分别等于所有进程的突发时间
对于(inti=0;i0){
//部分处决
if(rem_bt[pQueue.get(p)]>quantum){
//收集在执行过程中到达的所有进程
对于(int i=0;icpu\U时间和到达时间[i]cpu\u时间和到达时间[i]=1,则终止程序。但如果arrivalTime[0]为0,则会工作
for(int i=0;i
只需将此项添加到

    // get the processes by thier arrival time
            for( int i = 0; i < n; i++ ){
                if( arrivalTime[i] == cpu_time){
                    pQueue.add(i);
                }
            }
//按到达时间获取进程
对于(int i=0;i
在第一次只有

// get the processes by thier arrival time
        while( pQueue.isEmpty() ){
            for( int i = 0; i < n; i++){
                if( arrivalTime[i] == cpu_time){
                    pQueue.add(i);
                }
            }

            if( pQueue.isEmpty()){
                cpu_time++;
            }
        }
//按到达时间获取进程
while(pQueue.isEmpty()){
对于(int i=0;i
好像开始cpu时间为0,但他们的到达时间为0的进程不存在,甚至其他进程的cpu时间在任何进程添加到队列之前都不会更新。

您得到了一些吗