Search code examples
javaquartz-schedulerjobsjob-schedulingquartz

Whats the difference between the Job and JobDetail exactly in Quartz?


Why Quartz came up with separate class like JobDetail? when they can accommodate all properties in Job class only

Is it a implementation flaw from the authors?


Solution

  • first of all both are interfaces.

    an implementation of Job ie. its only method void execute(JobExecutionContext) is what gets called by the quartz scheduler in order to perform a desired task

    The interface to be implemented by classes which represent a 'job' to be performed.


    JobDetails are meta data related to a Job implementation, they hold a reference to the Job you want to run and allow you to provide some additional data to your Job

    Conveys the detail properties of a given Job instance. JobDetails are to be created/defined with JobBuilder.

    Quartz does not store an actual instance of a Job class, but instead allows you to define an instance of one, through the use of a JobDetail.

    Jobs have a name and group associated with them, which should uniquely identify them within a single Scheduler.


    this design decision here taken seems reasonable as it follows the separation of concerns approach.

    the Job to be performed gets all its input data through its JobExecutionContext and does not need to care about any other quartz related properties like name or group of the job.

    however, the quartz scheduler needs some additional information in order to run your Job. therefore, a JobDetail implementation is required holding this information.