Advertisement
Dr4noel

CevaTampit LA java

May 13th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. while(!AllProcesesAreComplete(executeTimeArray,nrOfProcess)){
  2. //The action that will take place on a quant
  3. for(int i = 0; i <= quantValue; i++){
  4. //we do the actions based on the current process --- this codes executes just when there are arivals time
  5. for(int j = 0; j < nrOfProcess; j++){
  6. //we verify if there is any process sheduled
  7. if(arrivalTimeArray[j] == time){
  8. //Mark the process as ready
  9. readyQueue[j] = nameOfProcess[j];
  10. displayArea.appendText(arrivalTimeArray[j] + "\t\t\t");
  11. //display all process that are ready to be procesed
  12. for(int rqp = 0; rqp < readyQueue.length; rqp++){
  13. if(readyQueue[rqp] != null){
  14. rqValues++;
  15. displayArea.appendText(readyQueue[rqp] + " ");
  16. }
  17. }
  18. //this will show the user the coresponding info
  19. if((time % quantValue) == 0){
  20. displayArea.appendText( "\t\t\t\t\t" + nameOfProcess[j] + " arrives and gets procesed \n");
  21. }else{
  22. displayArea.appendText( "\t\t\t\t\t" + nameOfProcess[j] + " arrives and waits for quantum to expire \n");
  23. }
  24. }
  25. }
  26. //we decrese the time of the running process
  27. glass = readyQueue[0];
  28. for(int index = 0; index < GetArrayNrOfValues(readyQueue) - 1; index++){
  29. if(((time % quantValue == 0) && (rqValues >= 2)) && (index < GetArrayNrOfValues(readyQueue) - 1)){
  30. readyQueue[index] = readyQueue[index + 1];
  31. }
  32. if(((index == GetArrayNrOfValues(readyQueue) - 1) && (rqValues >= 2)) && (time % quantValue == 0)){
  33. readyQueue[index] = glass;
  34. }
  35. }
  36.  
  37. for(int timedown = 0; timedown < nrOfProcess; timedown++){
  38. if(readyQueue[0].compareTo(nameOfProcess[timedown]) == 0){
  39. executeTimeArray[timedown] -= 1;
  40. }
  41. }
  42.  
  43. if(executeTimeArray[GetPositionOfAString(nameOfProcess,readyQueue[0])] == 0){
  44. glass = readyQueue[0];
  45. displayArea.appendText(time + "\t\t\t");
  46. for(int index = 0; index < GetArrayNrOfValues(readyQueue) - 1; index++){
  47. if(readyQueue[index] != null){
  48. readyQueue[index] = readyQueue[index + 1];
  49. displayArea.appendText(readyQueue[index] + "");
  50. }
  51. }
  52. if(executeTimeArray[GetPositionOfAString(nameOfProcess, glass)] != 0){
  53. readyQueue[GetArrayNrOfValues(readyQueue) - 1] = glass;
  54. displayArea.appendText("\t\t\t\tQuantum time " + quantValue + "ms expires, so " + glass + " is forced out of CPU and " + readyQueue[0] + " gets processed!\n");
  55. } else {
  56. readyQueue[GetArrayNrOfValues(readyQueue) - 1] = null;
  57. displayArea.appendText("\t\t\t\t" + glass + " got completed, so " + readyQueue[0] + " gets processed!\n");
  58. }
  59. }
  60.  
  61. //this variable keeps the track of the time(takes all interations that take place)
  62. //we verify if all the process are done
  63. if(AllProcesesAreComplete(executeTimeArray,nrOfProcess)){
  64. break;
  65. }
  66. time++;
  67. }
  68. quantNumber++;
  69. }
  70. }
  71. displayArea.appendText("\n The time was: " + (time + 1) + "\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement