ariestamirra

priority

May 22nd, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package Schedulling.priority;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. /**
  6.  *
  7.  * @author Mirra Ariesta Amalia Adiba
  8.  */
  9. public class Priority extends Schedulling.CpuScheduler{
  10.  
  11.     public Schedulling.Process getTopPriority(ArrayList<Schedulling.Process> processList){
  12.         Schedulling.Process result=null;        
  13.        
  14.         for (int i = 0; i < processList.size(); i++) {
  15.             if(result==null){
  16.                 result=processList.get(i);
  17.             }else{
  18.                 if(result.getPriority()>processList.get(i).getPriority()){                    
  19.                     result = processList.get(i);
  20.                 }
  21.             }
  22.         }
  23.        
  24.         return result;
  25.     }
  26.    
  27.     @Override
  28.     protected void execute() {
  29.         time = 0;
  30.         ArrayList<Schedulling.Process> queue;
  31.         while (getRemainingBurstTime() > 0) {
  32.            
  33.             if (getCurrent()!=null && (getCurrent().getCurrentBurstTime() <= 0 || getCurrent()!= getTopPriority(getProcessQueue(null))) ) {                
  34.                 detach();
  35.             }
  36.  
  37.             if (getCurrent() == null) {                
  38.                 attach(getTopPriority(getProcessQueue(null)));
  39.             }
  40.  
  41.             if (getCurrent() != null) {
  42.                 getCurrent().doProcess();
  43.             }
  44.  
  45.             queue = getProcessQueue(getCurrent());
  46.             queueWait(queue);
  47.             time++;
  48.         }
  49.         detach();
  50.    
  51.     }
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment