ariestamirra

rr2

May 25th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package Schedulling.roundRobin;
  2.  
  3. import Schedulling.CpuScheduler;
  4. import Schedulling.Process;
  5. import java.util.ArrayList;
  6.  
  7. /**
  8.  *
  9.  * @author Mirra Ariesta Amalia Adiba
  10.  */
  11. public class RoundRobin extends CpuScheduler {
  12.  
  13.     private int quantumTime = 0;
  14.  
  15.     public int getQuantumTime() {
  16.         return quantumTime;
  17.     }
  18.  
  19.     public void setQuantumTime(int quantumTime) {
  20.         this.quantumTime = quantumTime;
  21.     }
  22.  
  23.     public RoundRobin(int quantumTime) {
  24.         this.quantumTime = quantumTime;
  25.     }
  26.  
  27.     public RoundRobin() {
  28.     }
  29.  
  30.     public Process getNextProcess(ArrayList<Process> processList, Process before) {
  31.         if (getRemainingBurstTime() > 0 && processList.size() > 0) {
  32.             int index = processList.indexOf(before);
  33.             do {
  34.                 index++;
  35.                 if (index >= processList.size() || index < 0) {
  36.                     index = 0;
  37.                 }
  38.             } while (processList.get(index).getCurrentBurstTime() <= 0);
  39.             return processList.get(index);
  40.         }
  41.         return null;
  42.     }
  43.  
  44.     @Override
  45.     protected void execute() {
  46.         time = 0;
  47.         int currentQuantumTime = quantumTime;
  48.         Process before = null;
  49.         while (getRemainingBurstTime() > 0) {
  50.  
  51.             if (getCurrent() != null && (getCurrent().getCurrentBurstTime() <= 0 || currentQuantumTime <= 0)) {
  52.                 before = getCurrent();
  53.                 detach();
  54.                 currentQuantumTime = quantumTime;
  55.             }
  56.  
  57.             if (getCurrent() == null) {
  58.                 attach(getNextProcess(getProcessQueue(null), before));
  59.             }
  60.  
  61.             if (getCurrent() != null) {
  62.  
  63.                 getCurrent().doProcess();
  64.                 currentQuantumTime--;
  65.             }
  66.  
  67.             queueWait(getProcessQueue(getCurrent()));
  68.             time++;
  69.         }
  70.         detach();
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment