在使用quartz动态添加修改任务时,在新建trigger或者jobdetail时 除了给自己名称外,还有一个参数是groupname,这个参数是用来限制什么的呢?同一个组下的连个jobdetail 和两个组下的jobdetail有什么区别呢?trigger组在什么情况下会用到呢??
我使用的quartz是2.2.3的版本
请大神指教!!!
PHP中文网2017-04-18 10:28:25
The documentation is as follows:
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.
Simply put, name+group It forms a unique key, through which you can update, stop tasks, etc.
Write a simple 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);//暂停任务
Other applications of group:
You can get all the jobkeys under it through groupname
GroupMatcher<JobKey> gm = GroupMatcher.groupEquals("job-group");
Set<JobKey> set = scheduler.getJobKeys(gm);