In this assignment, you will create a priority job scheduler, based on the one used by operating systems to run applications. You will implement this with actual processes on an actual operating system when you take the operating systems class.

Task 1: Implement a Priority Queue using an array of queues. You can use the java.util.Queue or your own Queue implementation. The Queue should be able to support any type of object.

Task 2: In this assignment, you will use a Process object. Create a Process class that has three fields:
private String name; private int runtime; private int priority;

Task 3: Create a Scheduler class that has the following fields:
private final int TIME_SLICE = 100; private final int BOOST_TIME = 1000; private final int MAX_PRIORITY = 5; private PriorityQueue pq;

The scheduling algorithm in this assignment works as follows:
- When a process is added, it is placed at the scheduler-defined highest priority (defined by MAX_PRIORITY).
- The process with the highest priority runs first.
- The processing unit deals with one process for a period called a time slice. After spending that period working on one process,
- If the process completes before the time slice is up, it is removed from the scheduler.
- If the process does not complete, it is “aged”, i.e., it is removed from the current queue and added to the end of the next lower priority queue with a minimum priority of zero.
- When the “boost time” is up, all the jobs are removed from current queues and placed in the highest priority queue in order of pre-boosting priority.

Now, I will describe the five methods you have to implement in to get the scheduler algorithm to work.

public void init(): initialize the priority queue

public void addProcess(Process p): set the priority of p to MAX_PRIORITY and add it to priority queue
public void age(Process p): decrement the priority of p, and move it to the appropriate queue public void boost(Process p): set the priority of p to MAX_PRIORITY and move it to the appropriate queue
public void run(): this is a tricky method to implement, so read carefully. In an actual operating system, you will have a system clock that functions as a timer to determine when a certain time period runs out. Instead of incorporating an actual clock and making this assignment complex, we will just do a simple loop with a decrementing counter, i.e., the counter starts at the time period and decrements until 0, so when the “timer” ends, the count becomes zero. You will use three such “timers” – bCount for BOOST_TIME, tsCount for the TIME_SLICE, and rtCount for each process’s runtime.

The scheduler should run for as long as there are processes in its priority queue. Each time, it gets the process with the highest priority (notice I said get and not remove – hint, use peek). Both the time slice counter and the process runtime counter should start now, and repeat until one of them becomes zero. If the rtCount becomes zero first, remove the process from the priority queue since the process is done executing. If the rtCount is greater than zero when the tsCount is done, the process should be aged.

The bCount timer is continuously going from BOOST_TIME to zero and back to BOOST_TIME in the run() method. Every time it hits zero, all the processes should be boosted up to the highest priority queue.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.ArrayDeque;
import java.util.Queue;

public class PriorityQueue {

    private Queue<Process>[] arr;

    public PriorityQueue(int p_num) {
       arr = new Queue[p_num + 1];
       for (int i = 0; i < arr.length; i++) {
            arr[i] = new ArrayDeque<>();

    public void enqueue(Process t) {
       if (t != null) {

    public Process dequeue() {
       for (int i = arr.length - 1; i >= 0; i--) {
            if (arr[i].isEmpty() == false) {
                return arr[i].poll();
       return null;

    public Process peek() {
       for (int i = arr.length - 1; i >= 0; i--) {
            if (arr[i].isEmpty() == false) {
                return arr[i].peek();
       return null;

    public int size() {
       int size = 0;
       for (Queue<Process> q : arr) {
            size += q.size();            
       return size;

By purchasing this solution you'll be able to access the following files:

50% discount

$60.00 $30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats