Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble adding a Shortest Job First algorithm into my java code. I need the program to do these things: The program will

I am having trouble adding a Shortest Job First algorithm into my java code. I need the program to do these things:

The program will schedule the tasks using the First-Come, First-Served (FCFS), and Shortest Job First scheduling algorithms. The Program should be written in Java or C#. The student will take statistics and will write a paper describing what they found.

The FCFS algorithm should be run 3 times with the following ordering of threads:

1) All IOBound threads first

2) All CPUBound threads first

3) The 2 thread types interspersed

The statistics gathered should include:

1) Run time for each thread

2) Wait time for each thread

3) Average wait time for all threads

4) Average wait time for all CPUBound threads

5) Average wait time for all IOBound threads

6) Overall run time for all threads to run

I have gotten the First-Come, First-Served (FCFS) algorithm implemented and now I'm just struggling with the Shortest Job First algorithm and how to implement it into the existing code. The current controller thread code that I have is below:

****ThreadController.java****

public class ThreadController {

// number of objects of ThreadIo and computationThread class to be created static final int NUMBER_OF_THREADS = 5;

// create an array of 5 objects of each ThreadIo and computationThread // class ThreadIO IOobjects[] = new ThreadIO[NUMBER_OF_THREADS]; ThreadCPU computationThread[] = new ThreadCPU[NUMBER_OF_THREADS]; //Method to initialize the threads public void initilaizeThread(){ for (int i = 0; i < NUMBER_OF_THREADS; i++) { // initializing the objects IOobjects[i] = new ThreadIO(); IOobjects[i].setName("IO Thread " + (i + 1)); computationThread[i] = new ThreadCPU(); computationThread[i].setName("Computation Thread " + (i + 1));

} } //Method to start all IO threads public void startIOThreads(){ for (int j = 0; j < NUMBER_OF_THREADS; j++) { IOobjects[j].start(); // wait for the thread termination try { IOobjects[j].join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } //Method to start all Computation Threads public void startComputationThreads(){ for (int j = 0; j < NUMBER_OF_THREADS; j++) { computationThread[j].start(); // wait for the thread termination try { computationThread[j].join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } //Method to Print Results public void printResults(){ long totalExecutionTime = 0; long totalWaitTime = 0; System.out.println(); System.out.println(); System.out.println("******************************************************"); System.out.println("Computation time of IO Threads"); System.out.println("******************************************************"); for (int j = 0; j < NUMBER_OF_THREADS; j++) { if(IOobjects[j].startTime == 0){ continue; } totalExecutionTime += IOobjects[j].runningTime; totalWaitTime += IOobjects[j].waitTime; System.out.println("Wait Time of " + IOobjects[j].getName() + " :" + IOobjects[j].waitTime + " milliseconds"); System.out.println("Time taken by " + IOobjects[j].getName() + " to execute :" + IOobjects[j].runningTime + " milliseconds"); } System.out.println(); System.out.println(); System.out.println("******************************************************"); System.out.println("Computation time of Computational Threads"); System.out.println("******************************************************"); for (int j = 0; j < NUMBER_OF_THREADS; j++) { if(computationThread[j].startTime == 0){ continue; } totalExecutionTime += computationThread[j].runningTime; totalWaitTime += computationThread[j].waitTime; System.out.println("Wait Time of " + computationThread[j].getName() + " :" + computationThread[j].waitTime + " milliseconds"); System.out.println("Time taken by " + computationThread[j].getName() + " to execute :" + computationThread[j].runningTime + " milliseconds"); } System.out.println(); System.out.println(); System.out.println("******************************************************"); System.out.println("Total Execution Time is : "+totalExecutionTime); System.out.println("******************************************************"); System.out.println(); System.out.println(); System.out.println("******************************************************"); System.out.println("Total Wait Time is : "+totalWaitTime); System.out.println("******************************************************"); System.out.println(); System.out.println(); System.out.println("******************************************************"); System.out.println("Average Wait Time is : "+(totalWaitTime/NUMBER_OF_THREADS)); System.out.println("******************************************************"); System.out.println(); System.out.println(); }

public static void main(String[] args) throws InterruptedException {

long scheduleStartTime = 0; long scheduleEndTime = 0; ThreadController controller = new ThreadController(); controller.initilaizeThread(); // record the start schedule Time scheduleStartTime = System.currentTimeMillis(); controller.startComputationThreads(); controller.startIOThreads(); // record the end time of the schedule scheduleEndTime = System.currentTimeMillis(); //Print Results controller.printResults(); System.out.println("******************************************************"); System.out.println("Computation time of Schedule all the Threads"); System.out.println("******************************************************"); System.out.println("Time Taken to schedule and run all the threads: "+(scheduleEndTime -scheduleStartTime)+ " milliseconds"); }

}

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

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions