java - Quartz Scheduler: How to Group Jobs together? -
i wanted ask if had same problem quartz scheduler. created jobs trigger , jobkeys set groupnames. when print out group has been set default.
how can set groupname able group jobs , importantly cancel specified groups? code similar this:
public void unschedulebygroupname(string groupname) throws schedulerexception { (jobkey jobkey : scheduler.getjobkeys(groupmatcher.jobgroupequals(groupname))) { scheduler.unschedulejob(new triggerkey(jobkey.getname(), jobkey.getgroup())); } }
input:
triggerkey tkey = new triggerkey("trigger:" + jobname + "-somename:" + object.tostring(), "group:" + jobname + "-somename:" + object.tostring()); jobkey jkey = new jobkey("job:" + jobname + "-somename:" + object.tostring(), "group:" + jobname + "-somename:" + object.tostring()); jobdetail job = jobbuilder.newjob(somename.class).withdescription("somename") .withidentity(jkey).build(); trigger trigger = triggerbuilder.newtrigger().forjob(jkey).startat(new date()).withidentity(tkey).build();
output function:
for (string groupname : scheduler.getjobgroupnames()) { (jobkey jobkey : scheduler.getjobkeys(groupmatcher.jobgroupequals(groupname))) { string jobname = jobkey.getname(); string jobgroup = jobkey.getgroup(); // job's trigger list<trigger> triggers = (list<trigger>) scheduler.gettriggersofjob(jobkey); date nextfiretime = triggers.get(0).getnextfiretime(); system.out.println("[jobname] : " + jobname + " [groupname] : " + jobgroup + " - " + nextfiretime);}
output:
[jobname] : job:-somename:13 [groupname] : default - tue jul 19 13:48:40 cest 2016 [jobname] : job:-somename:14 [groupname] : default - tue jul 19 13:49:11 cest 2016 [jobname] : job:-somename:15 [groupname] : default - tue jul 19 13:49:41 cest 2016 [jobname] : job:-somename:16 [groupname] : default - tue jul 19 13:50:11 cest 2016
when seeing job identity, can add group info. chain methods below, , works me (i can see group desired name set):
jobdetail job = jobbuilder.newjob(scheduledjob.class) .withidentity("job key", "group name") .withdescription("job description") .usingjobdata(datamap) .build();
Comments
Post a Comment