Job Simulator in Java ------------ Sample Run #1: ***STARTING THE SIMULATION WITH PRIORITY MODE SET TO SORT_BY_PRIORITY*** Time Marker 0 waiting: 0 executing: NONE created:
Job Simulator in Java
------------
Sample Run #1:
***STARTING THE SIMULATION WITH PRIORITY MODE SET TO SORT_BY_PRIORITY***
Time Marker 0 waiting: 0
executing: NONE
created: Job #1 priority(1) created at 0, time left 4
Time Marker 1 waiting: 0
executing: Job #1 priority(1) created at 0, time left 4
Time Marker 2 waiting: 0
executing: Job #1 priority(1) created at 0, time left 3
created: Job #2 priority(2) created at 2, time left 5
Time Marker 3 waiting: 1
executing: Job #1 priority(1) created at 0, time left 2
Time Marker 4 waiting: 1
executing: Job #1 priority(1) created at 0, time left 1
completed: Job #1 at time 4
Time Marker 5 waiting: 0
executing: Job #2 priority(2) created at 2, time left 5
created: Job #3 priority(3) created at 5, time left 2
Time Marker 6 waiting: 1
executing: Job #2 priority(2) created at 2, time left 4
created: Job #4 priority(3) created at 6, time left 2
Time Marker 7 waiting: 2
executing: Job #2 priority(2) created at 2, time left 3
Time Marker 8 waiting: 2
executing: Job #2 priority(2) created at 2, time left 2
Time Marker 9 waiting: 2
executing: Job #2 priority(2) created at 2, time left 1
completed: Job #2 at time 9
Time Marker 10 waiting: 1
executing: Job #3 priority(3) created at 5, time left 2
created: Job #5 priority(3) created at 10, time left 2
Time Marker 11 waiting: 2
executing: Job #3 priority(3) created at 5, time left 1
created: Job #6 priority(3) created at 11, time left 3
completed: Job #3 at time 11
Time Marker 12 waiting: 2
executing: Job #4 priority(3) created at 6, time left 2
Time Marker 13 waiting: 2
executing: Job #4 priority(3) created at 6, time left 1
completed: Job #4 at time 13
Time Marker 14 waiting: 1
executing: Job #6 priority(3) created at 11, time left 3
Time Marker 15 waiting: 1
executing: Job #6 priority(3) created at 11, time left 2
Time Marker 16 waiting: 1
executing: Job #6 priority(3) created at 11, time left 1
completed: Job #6 at time 16
Time Marker 17 waiting: 0
executing: Job #5 priority(3) created at 10, time left 2
Time Marker 18 waiting: 0
executing: Job #5 priority(3) created at 10, time left 1
completed: Job #5 at time 18
Time Marker 19 waiting: 0
executing: NONE
created: Job #7 priority(1) created at 19, time left 4
Time Marker 20 waiting: 0
executing: Job #7 priority(1) created at 19, time left 4
created: Job #8 priority(3) created at 20, time left 5
Time Marker 21 waiting: 1
executing: Job #7 priority(1) created at 19, time left 3
Time Marker 22 waiting: 1
executing: Job #7 priority(1) created at 19, time left 2
Time Marker 23 waiting: 1
executing: Job #7 priority(1) created at 19, time left 1
completed: Job #7 at time 23
Time Marker 24 waiting: 0
executing: Job #8 priority(3) created at 20, time left 5
created: Job #9 priority(1) created at 24, time left 2
Time Marker 25 waiting: 1
executing: Job #8 priority(3) created at 20, time left 4
Time Marker 26 waiting: 1
executing: Job #8 priority(3) created at 20, time left 3
Time Marker 27 waiting: 1
executing: Job #9 priority(1) created at 24, time left 2
Time Marker 28 waiting: 1
executing: Job #9 priority(1) created at 24, time left 1
completed: Job #9 at time 28
Time Marker 29 waiting: 0
executing: Job #8 priority(3) created at 20, time left 2
Time Marker 30 waiting: 0
executing: Job #8 priority(3) created at 20, time left 1
completed: Job #8 at time 30
Time Marker 31 waiting: 0
executing: NONE
Time Marker 32 waiting: 0
executing: NONE
Time Marker 33 waiting: 0
executing: NONE
Time Marker 34 waiting: 0
executing: NONE
created: Job #10 priority(1) created at 34, time left 3
Time Marker 35 waiting: 0
executing: Job #10 priority(1) created at 34, time left 3
created: Job #11 priority(3) created at 35, time left 2
Time Marker 36 waiting: 1
executing: Job #10 priority(1) created at 34, time left 2
Time Marker 37 waiting: 1
executing: Job #10 priority(1) created at 34, time left 1
created: Job #12 priority(4) created at 37, time left 5
completed: Job #10 at time 37
.
.
.
.
Time Marker 98 waiting: 11
executing: Job #29 priority(3) created at 74, time left 1
completed: Job #29 at time 98
Time Marker 99 waiting: 10
executing: Job #36 priority(1) created at 97, time left 3
created: Job #37 priority(2) created at 99, time left 4
*************** Final Report: ***************
Active jobs:
Job #36 priority(1) created at 97, time left 2
Job #37 priority(2) created at 99, time left 4
Job #17 priority(3) created at 50, time left 2
Job #25 priority(3) created at 60, time left 2
Job #30 priority(3) created at 76, time left 4
Job #12 priority(4) created at 37, time left 2
Job #18 priority(4) created at 51, time left 5
Job #31 priority(4) created at 77, time left 5
Job #21 priority(4) created at 56, time left 2
Job #20 priority(4) created at 53, time left 4
Job #27 priority(4) created at 65, time left 4
Job #34 priority(4) created at 85, time left 3
The number of jobs currently executing is 12
The number of completed jobs is 25
The total number of jobs is 37
The average time left for unfinished jobs is 3.42
***END OF SIMULATION***
Application #4 Using ArrayDegue and priorityQueue classes from java.util write a program to simulate job scheduling in an operating system. Jobs are generated at random times. Each job is given: a random priority from 1 to 4, where 1 is the highest priority a random amount of time to complete its execution. Jobs do not begin execution and run to completion, but instead share the processor. The operating system executes a job for a fixed unit of time called a time slice. At the end of the time slice, the current job's execution is suspended, and the job is placed back on the priority queue, where it waits for its next share of processor time. The job having the highest priority is then removed from the priority queue and executed for the time slice. When a job is first generated, it will begin executing immediately if the processor is free. Otherwise it will be placed on the priority queue Since the job scheduling can be done not only by the priority but also by some other attributes add ability to run the simulation in two modes: 1. where jobs are ordered by their priority (compareTo 2. where jobs are ordered by their timeLeft (need to implement Comparator) SchedulingSimulation constructorwould take a parameter which will indicate the priority queue ordering: sORT_BY_PRIORITY or SORT_BY_LENGTHStep by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started