This Application relies on the features of java.util.Timer
and java.util.concurrent.PriorityBlockingQueue
.
Timer
provides the features of Scheduling aTimerTask
to either run at a specified Time (Schedule) or at any Fixed Duration repeated Execution.PriorityBlockingQueue
provides the features of extracting items with a defined priority.
The application exposes APIs for
- Creating a Job Definition.
- Scheduling a Job by id.
- Job Execution History.
The Application has 2 Logical Threads
SchedulerThread
which looks for Jobs to be scheduled in the next 5 minutes (This can be adjusted).JobEngineThread
this looks at the PriorityBlockingQueue and picks jobs based on the Priority.
- Create a New Job using the API
POST $hostname:8080/api/jobs
. - If the created job schedule is within 5 mins (Configurable) from now, it is added to execution Queue.
- If the schedule is after 5 mins, it is added to Job Definition Table.
JobEngineTask
picks up jobs to be executed from the execution queue and schedules it to be executed.JobExecutionTask
runs exactly at the specified time and updates the Job Execution Table after completion of Job.- The Job Schedule is cleaned Up.
- Steps
4 - 6
are run in an infinite loop.
Scheduler Workflow:
- It runs at every 10 seconds (Configurable), to check for jobs to be executed in the next 5 mins(Configurable).
- If there are jobs to be scheduled, then it is submitted to Job Engine for Scheduling.
H2
an in-memory database is used to store
JOB_DEFINITION
- definition of all jobs.JOB_EXECUTION
- stores history of all Job Execution, a job can have more than one execution.JOB_SCHEDULED
- stores information on all jobs that are QUEUED and RUNNING.