Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a Java project involving a CPU scheduling simulation. Instructions are at the bottom of the sets of code and text files. //=======rrschedule.txt=========================== T1,

This is a Java project involving a CPU scheduling simulation. Instructions are at the bottom of the sets of code and text files.

//=======rrschedule.txt===========================

T1, 40, 50 T2, 40, 50 T3, 40, 50 T4, 40, 50 T5, 40, 50 T6, 40, 50

//================run.txt========================= Priority with RR Scheduling

Will run Name: T8 Tid: 7 Priority: 10 Burst: 25

Task T8 finished.

Will run Name: T4 Tid: 3 Priority: 5 Burst: 15

Will run Name: T5 Tid: 4 Priority: 5 Burst: 20

Will run Name: T4 Tid: 3 Priority: 5 Burst: 5

Task T4 finished.

Will run Name: T5 Tid: 4 Priority: 5 Burst: 10

Task T5 finished.

Will run Name: T1 Tid: 0 Priority: 4 Burst: 20

Task T1 finished.

Will run Name: T2 Tid: 1 Priority: 3 Burst: 25

Will run Name: T3 Tid: 2 Priority: 3 Burst: 25

Will run Name: T7 Tid: 6 Priority: 3 Burst: 30

Will run Name: T2 Tid: 1 Priority: 3 Burst: 15

Will run Name: T3 Tid: 2 Priority: 3 Burst: 15

Will run Name: T7 Tid: 6 Priority: 3 Burst: 20

Will run Name: T2 Tid: 1 Priority: 3 Burst: 5

Task T2 finished.

Will run Name: T3 Tid: 2 Priority: 3 Burst: 5

Task T3 finished.

Will run Name: T7 Tid: 6 Priority: 3 Burst: 10

Task T7 finished.

Will run Name: T6 Tid: 5 Priority: 1 Burst: 10

Task T6 finished.

//==============schedule.txt================ T1, 4, 20 T2, 3, 25 T3, 3, 25 T4, 5, 15 T5, 5, 20 T6, 1, 10 T7, 3, 30 T8, 10, 25

//=============Driver.java========================== package cpuscheduling; import java.util.*; import java.io.*;

public class Driver{ public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("Usage: java Driver "); System.exit(0); } BufferedReader inFile = new BufferedReader(new FileReader(args[1])); String schedule; List queue = new ArrayList();// create the queue of tasks

// read in the tasks and populate the ready queue while ( (schedule = inFile.readLine()) != null) { String[] params = schedule.split(",\\s*"); queue.add(new Task(params[0], Integer.parseInt(params[1]), Integer.parseInt(params[2]))); } inFile.close(); Algorithm scheduler = null; String choice = args[0].toUpperCase(); switch(choice) { case "FCFS": scheduler = new FCFS(queue); break; case "SJF": scheduler = new SJF(queue); break; case "PRI": scheduler = new Priority(queue); break; case "RR": scheduler = new RR(queue); break; case "PRI-RR": scheduler = new PriorityRR(queue); break; default: System.err.println("Invalid algorithm"); System.exit(0); }

// start the scheduler scheduler.schedule(); } }

//===================CPU.java======================= package cpuscheduling; public class CPU { /** * Run the specified task for the specified slice of time. */ public static void run(Task task, int slice) { System.out.println("Will run " + task); } }

//==================Algorithm.java================= package cpuscheduling;

public interface Algorithm{ public abstract void schedule(); public abstract Task pickNextTask(); }

//====================Task.java==================== package cpuscheduling; import java.util.concurrent.atomic.AtomicInteger;

public class Task{ // the representation of each task private String name; private int tid; private int priority; private int burst; /** We use an atomic integer to assign each task a unique task id.*/ private static AtomicInteger tidAllocator = new AtomicInteger();

public Task(String name, int priority, int burst) { this.name = name; this.priority = priority; this.burst = burst;

this.tid = tidAllocator.getAndIncrement(); }

/** Appropriate getters*/ public String getName() { return name; }

public int getTid() { return tid; }

public int getPriority() { return priority; }

public int getBurst() { return burst; }

/** * Appropriate setters */ public int setPriority(int priority) { this.priority = priority;

return priority; } public int setBurst(int burst) { this.burst = burst;

return burst; }

/** We override equals() so we can use a Task object in Java collection classes.*/ public boolean equals(Object other) { if (other == this) return true;

if (!(other instanceof Task)) return false;

/** * Otherwise we are dealing with another Task. * two tasks are equal if they have the same tid. */ Task rhs = (Task)other; return (this.tid == rhs.tid) ? true : false; }

public String toString() { return "Name: " + name + " " + "Tid: " + tid + " " + "Priority: " + priority + " " + "Burst: " + burst + " "; } }

Completing it will require writing the following Java classes:

FCFS.java SJF.java RR.java Priority.java PriorityRR.java

Each of the classes (FCFS.java, SJF.java, RR.java, Priority.java and PriorityRR.java) must be created and must implement the code above. These classes have not been created yet and must implement the formulas and process related to each technique.

RR - Round Robin

SJF - shortest job first.

Priority - priority first.

FCFS - first-come first-serve (FIFO)

PriorityRR - Round Robin with priority in mind.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions