Coders Packet

Job Scheduling with deadlines in Java

By Matam Deekshith

In this java tutorial, we will learn how to schedule the processes based on their deadlines and determine if they can be executed within their deadline or not


   We are given with process id, its burst time and, deadline. (Burst time means the amount of time required by a process to complete the task once it is started). Among all the given processes we will find out the processes which can be completed within the deadline.

   Let us consider an example to understand how scheduling is performed



NOTE:  We are assuming that all processes arrived at time =0

On performing the job scheduling based on deadline:

      processes with id 1 and 2 can only be scheduled and the rest of the processes can't be completed since their deadlines are exceeded.


  In the below code we make use of two methods namely check() and sort() respectively. Initially, with the given input we check if any process's burst time itself exceeds the deadline and eliminate those, since they can't be completed even though if they are started at time=0. Also, we are returned with the value representing the number of such processes after completing the check() method. Whereas in the sort() method we do sort the processes based on the deadlines associated.

Finally, those processes are scheduled whose completion time is less than or equal to the deadline.


task 0 can't be performed since burst time is greater than the deadline

task 4 can't be performed since burst time is greater than the deadline

Process 2 is completed at 2 seconds

Process 1 is completed at 5 seconds

task 4 can't be performed since the completion time is greater than the deadline


Download Complete Code


No comments yet