Quarz 常用范式

Quaz  is a very common library for us to use to scheudle  regular jobs.  

Just record the paradism to use the Quarz 

1,  SchedulerFactory to initialize a scheduler to use, there might be several kinds of schedulers to use

     base on the property configuration, for example the thread pool size, the thread pool name

2, Once the scheduler is created, we can start the scheduler. Only the scheudler is started, we can use it. 

3, We can created a JobDetail with the Job class type to schedule a new Job with the crontrigger, which is used to specify the executing freqency of the Job.

       JobDetail  jobDetail = new JobDetail( jobName, jobGroupName, jobClassType);

                 JobDataMap is key/value map to specify the context, or the real parameter of the Job 

4,  We define the Job class type in the step 3.  It's better to define a StatefulJob for the Job , the execute method will be called back when a new Job triggered by the scheduler

      use the JobDataMap() to get the paramter to do the things.

5,  If we want to manage the scheduler life cycle , we can call its scheduler.stop 

There are quite a few defects we have faced in different version of quarz,  so we are using its stable version

1.6.5 .

  

猜你喜欢

转载自bruce008.iteye.com/blog/2304920