JOB state and concurrency

Because each job will create a new instance is executed,

         When jobDetail example, the data to be stored or special field operation, data need schedul performed before each job retention time,

            Then we need job information before the data kept under the state has to avoid every scheduler re-create a new instance of a stateless,

 

JobDetail = JobBuilder the JobDetail. NewJob (QuartzJob. Class) 
.withIdentity ( "The myjob", "Group")
// JobDataMap when building JobDetail, data can be placed in the JobDataMap,
.usingJobData ( "jobSays", "the Hello World!")
.usingJobData ( "myFloatValue", 3.14f)
.usingJobData ( "COUNT", 0)
.build ();





/ ** 
*: The annotation is added to the job class, do not perform the same Quartz tell a defined job concurrently (in this particular job class) multiple instances.
* Please note that the wording here. Take the example of the previous section, a
* if the annotations on "SalesReportJob" category,
* the same time allows only one instance of "SalesReportForJoe",
* but one example, may be performed concurrently "SalesReportForMike" category.
* The limits are so JobDetail, rather than job classes.
* However, we believe (in the design of Quartz time) should be the annotation on the job class,
* because of changes in job categories will often lead to behavior change.
* /
@DisallowConcurrentExecution // These are official documents bunch of nonsense, sum up by saying that, to limit job instances (jobDetai) is concurrent execution
/ ** This comment 
* when multiple calls for job job will be persistent, that is, save certain information
This comment is not every instance creates a jobDataMap will not save the information you created previously 
* /
@PersistJobDataAfterExecution
public class QuartzJob the implements the Job {
 @Override public void the Execute (JobExecutionContext JobExecutionContext) throws JobExecutionException {  ++ COUNT;  . System out.println (.. JobExecutionContext.getJobDetail () getKey () getName () + "is the first" + COUNT + "invocation"); JobExecutionContext. .. getJobDetail () getJobDataMap () PUT ( "COUNT", COUNT); // System.out.println ( "get here is the number of fusion Map less than once a specified number of jobDetailMap of jobDwtail"); // JobExecutionContext. . getMergedJobDataMap () PUT ( "COUNT", COUNT); // System.out.println (. jobExecutionContext.getMergedJobDataMap () getIntValue ( "COUNT"));} }











Myjob by the first invocation
myjob is called 2nd
myjob is the third call

record state jobDetail

Guess you like

Origin www.cnblogs.com/wangbiaohistory/p/12040157.html