i was given an assignment .
Write a program to simulate job scheduling in an operating system.
Jobs are generated at random times. Each job is given both a random
priority from 1 to 4 – where 1 is the highest priority –and 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 time slice. At the end of the time slice, the current
job’s execution is suspended. The job is then placed on a 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 a 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.In this assignment, you will need an implementation of a queue and a
priority queue. You can use the priority queue in the Java Class
Library (java.util.PriorityQueue). It implements the interface
java.util.Queue.
im confuse with time slice and execution time..
as my understanding for now is let say final int timeslice=3, the time to complete all job is final int clock=20 minutes.;
when job A begin at 0 minute has execution time of 5(which is randomly generated between 1-5).
while executing the job till minute 3.Job A is put into priority queue while Job B with execution time of 2 minute enters at minute 3? after finish executing Job B, Job A enter to finish executing or Job C ?
please explain if im wrong. Thanks
In your question of whether Job A or Job C is executed (once B is complete) it should depend what the PriorityQueue returns, which will be the job with the highest priority.
If Job A had a priority of 1 and Job C a priority of 2, PriorityQueue would return Job A and that should get the next time slice.
If Job C had a priority of 2 and Job B a priority of 4, PriorityQueue would return Job C and that should get the next time slice.
As adn_295 says, this is a good assignment.