Advertisement
jamius19

SJF Preemtive

Mar 3rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package thread;
  2.  
  3. public class Main {
  4.    
  5.    
  6.     static Process[] p = new Process[4];
  7.    
  8.     public static void main(String[] args) {
  9.        setValues();
  10.        
  11.         for (int i = 0; i < 25; i++) {
  12.             int lowIndex = -1, lowVal = Integer.MAX_VALUE;
  13.  
  14.             for (int j = 0; j < p.length; j++) {
  15.                 if(p[j].arrivalT <= i && p[j].burstT < lowVal){  
  16.                     lowIndex = j;
  17.                     lowVal = p[j].burstT;
  18.                 }
  19.             }
  20.            
  21.            
  22.         }
  23.     }
  24.    
  25.     static void setValues(){
  26.         for (int i = 0; i < p.length; i++) {
  27.             switch(i){
  28.                 case 0 : p[i] = new Process(i, 10, 3);
  29.                 break;
  30.                 case 1 : p[i] = new Process(i, 5, 0);
  31.                 break;
  32.                 case 2 : p[i] = new Process(i, 3, 8);
  33.                 break;
  34.                 case 3 : p[i] = new Process(i, 8, 5);
  35.                 break;
  36.             }
  37.         }
  38.        
  39.         for (int i = 0; i < p.length - 1; i++)  
  40.         {  
  41.             int index = i;  
  42.             for (int j = i + 1; j < p.length; j++){  
  43.                 if (p[j].arrivalT <= p[index].arrivalT){  
  44.                     index = j;
  45.                    
  46.                     if (p[j].arrivalT == p[index].arrivalT){
  47.                           if (p[j].burstT < p[index].burstT){
  48.                               index = j;
  49.                           } else {
  50.                               index = i;
  51.                           }
  52.                     }
  53.                 }  
  54.             }  
  55.             Process pT = p[index];  
  56.             p[index] = p[i];  
  57.             p[i] = pT;  
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement