Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.raizal.roundRobin;
- import com.raizal.CpuScheduler;
- import java.util.ArrayList;
- import com.raizal.Process;
- public class RoundRobin extends CpuScheduler {
- private int quantumTime = 0;
- public int getQuantumTime() {
- return quantumTime;
- }
- public void setQuantumTime(int quantumTime) {
- this.quantumTime = quantumTime;
- }
- public RoundRobin(int quantumTime) {
- this.quantumTime = quantumTime;
- }
- public RoundRobin() {
- }
- public Process getNextProcess(ArrayList<Process> processList, Process before) {
- if (getRemainingBurstTime() > 0 && processList.size() > 0) {
- int index = processList.indexOf(before);
- do {
- index++;
- if (index >= processList.size() || index < 0) {
- index = 0;
- }
- } while (processList.get(index).getCurrentBurstTime() <= 0);
- return processList.get(index);
- }
- return null;
- }
- @Override
- protected void execute() {
- time = 0;
- int currentQuantumTime = quantumTime;
- Process before = null;
- while (getRemainingBurstTime() > 0) {
- if (getCurrent() != null && (getCurrent().getCurrentBurstTime() <= 0 || currentQuantumTime <= 0)) {
- before = getCurrent();
- detach();
- currentQuantumTime = quantumTime;
- }
- if (getCurrent() == null) {
- attach(getNextProcess(getProcessQueue(null), before));
- }
- if (getCurrent() != null) {
- getCurrent().doProcess();
- currentQuantumTime--;
- }
- queueWait(getProcessQueue(getCurrent()));
- time++;
- }
- detach();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment