java - quartz里关于group的问题
PHP中文网
PHP中文网 2017-04-18 10:26:25
0
1
831

在使用quartz动态添加修改任务时,在新建trigger或者jobdetail时 除了给自己名称外,还有一个参数是groupname,这个参数是用来限制什么的呢?同一个组下的连个jobdetail 和两个组下的jobdetail有什么区别呢?trigger组在什么情况下会用到呢??

我使用的quartz是2.2.3的版本
请大神指教!!!

PHP中文网
PHP中文网

认证高级PHP讲师

Antworte allen(1)
洪涛

文档如下:
The keys of Jobs and Triggers (JobKey and TriggerKey) allow them to be placed into ‘groups’ which can be useful for organizing your jobs and triggers into categories such as “reporting jobs” and “maintenance jobs”. The name portion of the key of a job or trigger must be unique within the group - or in other words, the complete key (or identifier) of a job or trigger is the compound of the name and group.
简单说,name+group才是组成一个唯一key,通过key可以更新、停止任务等等。
写个简单的demo:

           JobDetail jobDetail=JobBuilder.newJob(SimpleJob.class).withIdentity("myjob", "job-group").build();
           CronTrigger cronTrigger=TriggerBuilder.newTrigger().withIdentity("cronTrigger", "trigger-group").withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?")).build();  
           SchedulerFactory sFactory=new StdSchedulerFactory();  
           Scheduler scheduler=sFactory.getScheduler();  
           scheduler.scheduleJob(jobDetail, cronTrigger);
           scheduler.start();  
           Thread.sleep(5*1000);//
           JobKey key = JobKey.jobKey("myjob", "job-group");//通过name+group获取唯一的jobKey
           scheduler.pauseJob(key);//暂停任务

group的其他应用:
可以通过groupname来获取其下的所有jobkey


  GroupMatcher<JobKey> gm = GroupMatcher.groupEquals("job-group");
  Set<JobKey> set = scheduler.getJobKeys(gm);
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage