Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while(!AllProcesesAreComplete(executeTimeArray,nrOfProcess)){
- //The action that will take place on a quant
- for(int i = 0; i <= quantValue; i++){
- //we do the actions based on the current process --- this codes executes just when there are arivals time
- for(int j = 0; j < nrOfProcess; j++){
- //we verify if there is any process sheduled
- if(arrivalTimeArray[j] == time){
- //Mark the process as ready
- readyQueue[j] = nameOfProcess[j];
- displayArea.appendText(arrivalTimeArray[j] + "\t\t\t");
- //display all process that are ready to be procesed
- for(int rqp = 0; rqp < readyQueue.length; rqp++){
- if(readyQueue[rqp] != null){
- rqValues++;
- displayArea.appendText(readyQueue[rqp] + " ");
- }
- }
- //this will show the user the coresponding info
- if((time % quantValue) == 0){
- displayArea.appendText( "\t\t\t\t\t" + nameOfProcess[j] + " arrives and gets procesed \n");
- }else{
- displayArea.appendText( "\t\t\t\t\t" + nameOfProcess[j] + " arrives and waits for quantum to expire \n");
- }
- }
- }
- //we decrese the time of the running process
- glass = readyQueue[0];
- for(int index = 0; index < GetArrayNrOfValues(readyQueue) - 1; index++){
- if(((time % quantValue == 0) && (rqValues >= 2)) && (index < GetArrayNrOfValues(readyQueue) - 1)){
- readyQueue[index] = readyQueue[index + 1];
- }
- if(((index == GetArrayNrOfValues(readyQueue) - 1) && (rqValues >= 2)) && (time % quantValue == 0)){
- readyQueue[index] = glass;
- }
- }
- for(int timedown = 0; timedown < nrOfProcess; timedown++){
- if(readyQueue[0].compareTo(nameOfProcess[timedown]) == 0){
- executeTimeArray[timedown] -= 1;
- }
- }
- if(executeTimeArray[GetPositionOfAString(nameOfProcess,readyQueue[0])] == 0){
- glass = readyQueue[0];
- displayArea.appendText(time + "\t\t\t");
- for(int index = 0; index < GetArrayNrOfValues(readyQueue) - 1; index++){
- if(readyQueue[index] != null){
- readyQueue[index] = readyQueue[index + 1];
- displayArea.appendText(readyQueue[index] + "");
- }
- }
- if(executeTimeArray[GetPositionOfAString(nameOfProcess, glass)] != 0){
- readyQueue[GetArrayNrOfValues(readyQueue) - 1] = glass;
- displayArea.appendText("\t\t\t\tQuantum time " + quantValue + "ms expires, so " + glass + " is forced out of CPU and " + readyQueue[0] + " gets processed!\n");
- } else {
- readyQueue[GetArrayNrOfValues(readyQueue) - 1] = null;
- displayArea.appendText("\t\t\t\t" + glass + " got completed, so " + readyQueue[0] + " gets processed!\n");
- }
- }
- //this variable keeps the track of the time(takes all interations that take place)
- //we verify if all the process are done
- if(AllProcesesAreComplete(executeTimeArray,nrOfProcess)){
- break;
- }
- time++;
- }
- quantNumber++;
- }
- }
- displayArea.appendText("\n The time was: " + (time + 1) + "\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement