ariestamirra

fifofifofifofifo

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