Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Schedulling.fifo;
- import Schedulling.CpuScheduler;
- import java.util.ArrayList;
- import Schedulling.Process;
- import Schedulling.Time;
- /**
- *
- * @author Mirra Ariesta Amalia Adiba
- */
- public class Fifo extends CpuScheduler {
- private Process getSmallestArrival(ArrayList<Process> queue) {
- Process result = null;
- if (queue.size() > 0) {
- result = queue.get(0);
- }
- for (int i = 0; i < queue.size(); i++) {
- if (result.getArrivalTime() > queue.get(i).getArrivalTime()) {
- result = queue.get(i);
- }
- }
- return result;
- }
- @Override
- protected void execute() {
- time = 0;
- while (getRemainingBurstTime() > 0) {
- if (getCurrent() != null && getCurrent().getCurrentBurstTime() <= 0) {
- detach();
- }
- if (getCurrent() == null) {
- attach(getSmallestArrival(getProcessQueue(null)));
- }
- if (getCurrent() != null) {
- getCurrent().doProcess();
- }
- queueWait(getProcessQueue(getCurrent()));
- time++;
- }
- detach();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment