Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below you will see an example that does somethign similar(This already does the FCFS method), it needs more working threads added plus needs to make

image text in transcribed

Below you will see an example that does somethign similar(This already does the FCFS method), it needs more working threads added plus needs to make sure all algorithms can be used so data can be collected.

1.Wait time is

Time to get CPU (Time between , time when Thread.start is called and

time when "run" method is started (means thread get CPU)

Time for IO wait

Only applicable for IO thread

Time waited for System.out.printl to complete (not accurate)

2.We can't calculate exact wait time

3. I created following variable in each type of Thread class

long startTime,stopTime,runningTime , waitTime , startExecutionTime; startTime When called Thread.Start startExecutionTime when run method started execution (get the CPU) stopTime is when run() method completed waitTime is Time Difference between startTime,startExecutionTime + wait for IO

4. Please check comments in Code

5. startIOThreads ,startComputationThreads methods are used to start certain type of threads

We can re arrange calling these methods to start required threds first

for example if we want start IOThreads first the

startIOThreads()// First statement

startComputationThreads() /ext

you can comment the requied method if you don't want to start any kind of threads

comment calling of startIOThreads()if you don't want to start IO threads

Code

ThreadIO.java :-

-------------------------

/** * * @author This thread perform the IO operation * */ public class ThreadIO extends Thread { //Variable for Start and Stop time... /** * startTime When called Thread.Start * startExecutionTime when run method started execution (get the CPU) * stopTime is when run() method completed * waitTime is Time Difference between startTime,startExecutionTime + wait for IO */ long startTime,stopTime,runningTime , waitTime , startExecutionTime; @Override public synchronized void start() { // set Start time to current System time startTime = System.currentTimeMillis(); // TODO Auto-generated method stub super.start(); } @Override // define the body which need to be executed by the thread public void run() { // set Start Execution time to current System time startExecutionTime = System.currentTimeMillis(); for (int i = 0; i

}

ComputationThread.java

------------------------------------------

public class ComputationThread extends Thread {

int a = 3; int b = 6; //Variable for Start and Stop time... /** * startTime When called Thread.Start * startExecutionTime when run method started execution (get the CPU) * stopTime is when run() method completed * waitTime is Time Difference between startTime,startExecutionTime */ long startTime,stopTime,runningTime , waitTime , startExecutionTime; @Override public synchronized void start() { // set Start time to current System time startTime = System.currentTimeMillis(); // TODO Auto-generated method stub super.start(); }

@Override // define the body which need to be executed by the thread public void run() { // set Start Execution time to current System time startExecutionTime = System.currentTimeMillis(); //Computation Thread should not do any I/O like System.out.println so remove for (int i = 0; i

ControllerThread.java

------------------------------------------

/** * * @author Controls all the threads * */ public class ControllerThread {

// 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]; ComputationThread computationThread[] = new ComputationThread[NUMBER_OF_THREADS]; //Method to initialize the threads public void initilaizeThread(){ for (int i = 0; i

} } //Method to start all IO threads public void startIOThreads(){ for (int j = 0; j

long scheduleStartTime = 0; long scheduleEndTime = 0; ControllerThread controller = new ControllerThread(); controller.initilaizeThread(); // record the start schedule Time scheduleStartTime = System.currentTimeMillis(); //Re Arrange of Execution of IO/Computation threads //If you don't want to start certain type of Thread then comment 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"); }

}

The project will consist of creating a simulation of an operating system scheduler handling multiple threads or processes. The student will create a program that launches 6 10 worker threads simulating a processor bound, I/O bound and an intermediate of the two types. The program will schedule the tasks using the First-Come, First-Served FCFS), Shortest Job First, and Round Robin scheduling algorithms. The Program should be written in Java and the Round Robin algorithm should employ the suspendo and resume0 thread methods (yes I know the methods are depreciated. Included as an attachment is a sample). The student will take statistics and will write a paper describing what they found

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

What is the difference between data, information, and intelligence?

Answered: 1 week ago