A task is a class that implements the job interface. As shown below, there is only one method for the job interface.
Package Org.quartz; Public interface Job {public void execute (jobexecutioncontext context) throws jobexecutionexception; }
When a Job trigger is triggered, the scheduler takes a thread from the pool of threads to invoke execute (..) Method. The Jobexecutioncontext method has a parameter that can be used to obtain information about the job runtime, such as the scheduler performing one of its processing, the job's Jobdetail object, and so on.
When the Quartz client adds the job to the scheduler, the Jobdetail instance is created. This object has a variety of properties that are used to configure the job. There is also a jobdatamap that holds state information for instances of the job class. The Jobdetail object can construct a Job instance.
The Trigger object can trigger the execution of the job. When you want to schedule a job, you need to initialize a trigger object and set the properties you need based on your needs.
Trigger also has jobdatamap, trigger is triggered, jobdatamap can be a good pass parameter to the job. Quartz provides some useful trigger types, but the most common types of triggers are Simpletrigger and Crontrigger.
- Simpletrigger: If you need to do it at some point in time, or you need to do it at some point in time (n times ).
- Crontrigger: If you imagine the time schedule on the calendar to execute, for example, every morning at 5 o ' Day.
Why are Jobs and Triggers? Many task schedulers do not separate the concepts of jobs and Triggers. Some schedulers simply use the job as an execution time, as well as some small job identities. Other schedulers confuse the concept of Jobs and Triggers. Quartz's design separates the execution plan from the specific business work. It's going to be fine.
As an example, you can create a job and save it in the job scheduler. In this case, you can associate the job with many Trigger. One benefit of the exception is the realization of understanding decoupling.
Quartz Study of Jobs and Triggers