Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Example Output Problem Statement You are to develop a Java program to simulate the creation and execution of prioritized processes. You will need to implement

image text in transcribed
Example Output
image text in transcribed
Problem Statement You are to develop a Java program to simulate the creation and execution of prioritized processes. You will need to implement the following data types to support the simulation: A node type to represent a process. The node will contain a process id, a priority and a time slice (in milliseconds). The time slice indicates how long the process will "run" (i.e. sleep). A Min-Heap to store the process nodes so that a node with the lowest priority number is at the top of the heap ready to go when the next process is chosen. (NOTE: in many priority-based systems, priority O is the highest priority. IE the lower the number, the higher the priority). Because all of the threads in your program need to access this heap data structure, you must synchronize access to the operations on the heap that must not be interrupted before completion. A runnable/thread type to "consume"/retrieve a node off the top of the heap. The thread will simulate execution by sleeping for the duration of the time slice. When a process has completed its "execution," the thread reports the process id, its priority value, and the time when it completed. Use a single line for the report, and make sure that the time is precise enough to see sub-second execution times. o If there is no work available on the heap, the thread must go to sleep for some pre-determined idle time in milliseconds. A second runnable/thread type to create and add processes to the heap. Let this thread wake up at random periodic intervals and add some new processes into the heap occasionally. this thread should wake up at least 3 times and add processes. It should not run forever Your main program will create a single heap. Your main program should spawn 2 instances of your consumer threads. The main program should pass a reference to the shared heap to all of its threads upon creation. Your consumer threads will pull the next available process off the heap and do their work. Your main program should spawn the thread that adds processes to the heap. Your program can detect that the producer thread is complete, and can then monitor the heap until it is empty. It must then notify the other idle consumer threads to exit. Consumer 1 is starting... Starting Producer... Producer Adding Nodes Consumer 2 is starting... Consumer 1 is idle Consumer 2 is idle Producer thinks there are 25 Nodes in queue Consumer 1 finished Process: 4 pri: 0 at 1581445834598 Consumer 1 finished Process: 10 pri: 0 at 1581445835095 Consumer 1 finished Process: 2 pri: 1 at 1581445835465 Consumer 1 finished Process: 1 pri: 1 at 1581445835538 Consumer 2 finished Process: 18 pri: 1 at 1581445835546 Consumer 1 finished Process: 8 pri: 2 at 1581445835693 Consumer 1 finished Process: 3 pri: 2 at 1581445835852 Consumer 2 finished Process: 5 pri: 2 at 1581445836035 Producer Adding Nodes Producer thinks there are 40 Nodes in queue Consumer 1 finished Process: 16 pri: 3 at 1581445836193 Consumer 1 finished Process: 26 pri: 0 at 1581445836451 Consumer 2 finished Process: 17 pri: 3 at 1581445836468 Consumer 2 finished Process: 48 pri: 0 at 1581445836653 Consumer 2 finished Process: 36 pri: 1 at 1581445836654 Consumer 1 finished Process: 29 pri: 0 at 1581445836845 Consumer 1 finished Process: 39 pri: 1 at 1581445836913 Consumer 1 finished Process: 27 pri: 2 at 1581445836973 Consumer 2 finished Process: 38 pri: 1 at 1581445837011 Consumer 2 finished Process: 14 pri: 3 at 1581445837078 Consumer 1 finished Process: 46 pri: 3 at 1581445837190 Consumer 2 finished Process: 50 pri: 3 at 1581445837221 Consumer 1 finished Process: 41 pri: 3 at 1581445837537 Consumer 2 finished Process: 42 pri: 4 at 1581445837698 Consumer 1 finished Process: 22 pri: 5 at 1581445837715 Consumer 1 finished Process: 45 pri: 5 at 1581445837899 Consumer 2 finished Process: 25 pri: 5 at 1581445838023

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 And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

Physical pain and eudaimonic wellbeing.

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago