Class RRScheduler
java.lang.Object
|
+--Scheduler
|
+--RRScheduler
- public class RRScheduler
- extends Scheduler
A round-robin Scheduler for a CPU.
It maintains a linked list of jobs.
This scheduler is remarkably similar to the DiskScheduler.
Method Summary |
boolean |
add(Job newJob,
Job currentJob)
Add a new job wanting service. |
void |
printQueue()
For debugging: print the queue of waiting jobs |
Job |
remove()
Retrieve (and remove) the next job to be served. |
boolean |
reschedule(Job j)
This method is called when there is a clock interrupt and decides
whether to preempt the current job. |
java.lang.String |
toString()
For debugging: a concise version of the queue |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
RRScheduler
public RRScheduler()
add
public boolean add(Job newJob,
Job currentJob)
- Add a new job wanting service.
For RR, it simply goes to the end of the queue.
- Overrides:
- add in class Scheduler
- Parameters:
newJob
- the job newly awaiting service for the device.currentJob
- the job currently using the device, if any (ignored)- Returns:
- false (this scheduler never preempts)
remove
public Job remove()
- Retrieve (and remove) the next job to be served.
- Overrides:
- remove in class Scheduler
- Returns:
- the next job (null if there is no such job).
reschedule
public boolean reschedule(Job j)
- This method is called when there is a clock interrupt and decides
whether to preempt the current job.
For RR scheduling it returns true if the queue is non-empty and false
otherwise (if nobody is waiting, the current job might as well
continue).
- Overrides:
- reschedule in class Scheduler
- Parameters:
j
- the job currently being serviced by the corresponding device.- Returns:
- true if the scheduler wants to preempt the current job.
printQueue
public void printQueue()
- For debugging: print the queue of waiting jobs
- Overrides:
- printQueue in class Scheduler
toString
public java.lang.String toString()
- For debugging: a concise version of the queue
- Overrides:
- toString in class java.lang.Object
- Returns:
- a concise version of the queue of waiting jobs