ariestamirra

fifo

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