Как бы я перевел с FCFS на Round Robin? - PullRequest
0 голосов
/ 28 марта 2019

Насколько я понимаю, единственная разница между FCFS и Round Robin заключается в том, что один использует "временной интервал", так что процесс может использовать только это количество времени на время выполнения.

Пожалуйста, найдите мою программу планировщика FCFS:

import java.util.Queue;
import java.util.LinkedList;

public class Fcfs extends Scheduler {

  private Queue<Process> readyQueue;


  public Fcfs() {
    readyQueue = new LinkedList<Process>();
  }

  //adds a process to the ready queue
  public void ready(Process process, boolean finTimeQuantum) {
    readyQueue.offer(process);
  }

  //removes the next process to be run from the ready queue and returns it
  public Process schedule() {
    System.out.println("Scheduler selects process "+readyQueue.peek());
    return readyQueue.poll();
  }
}

А теперь, когда я сделал это, я не понимаю, как реализовать срез? Я хотел бы пойти дальше и начать как:

public class Rr extends Scheduler {
    private Queue<Process> readyQueue;
    private final int quantum; //this is the slicer
    private int i; //assuming I need a counter

    public Rr() {
        readyQueue = new LinkedList<Process>();
        quantum = super.getTimeQuantum();

    //Process process gives you process with parameters
    //boolean finTimeQuantum is true if process is being moved to ready after having fully its quantum.
    public void ready(Process process, boolean finTimeQuantum) {
        //though now I've no idea what to do?

Поскольку я сейчас делаю Round Robin, я бы предположил, что я не пойду и сразу .offer () первый процесс, который приходит. Или, может быть, вы делаете?

...