我正在使用石英调度程序,它工作正常。我有以下 cron 工作:
<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData
http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">
<schedule>
<job>
<name>SendSmsEveryMinute</name>
<group>EveryMinuteGroup</group>
<description>Run a Job Every Minute</description>
<job-class>com.sk.model.SendSMSMain</job-class>
</job>
<trigger>
<cron>
<name>dummyTriggerName</name>
<job-name>SendSmsEveryMinute</job-name>
<job-group>EveryMinuteGroup</job-group>
<!-- It will run every 1 minute -->
<cron-expression>0 0/1 * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
现在,从现在开始,我每隔一分钟就解雇一次工作。(如果我错了,请纠正我。)。好吧,现在我想在石英调度程序中显示所有作业,我的代码是:
public SchedulerViewer() throws SchedulerException {
ServletContext servletContext = (ServletContext) FacesContext
.getCurrentInstance().getExternalContext().getContext();
//Get QuartzInitializerListener
StdSchedulerFactory stdSchedulerFactory = (StdSchedulerFactory) servletContext.getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);
scheduler = stdSchedulerFactory.getScheduler();
// loop jobs by group
for (String groupName : scheduler.getJobGroupNames()) {
// get jobkey
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
String jobName = jobKey.getName();
String jobGroup = jobKey.getGroup();
// get job's trigger
List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
Date date = triggers.get(0).getNextFireTime();
//converting to joda time
DateTime dateTime = date == null ? null : new DateTime(triggers.get(0).getNextFireTime());
DateTimeZone tz = DateTimeZone.forID("Asia/Kathmandu");
System.out.println("TZ:0--------->"+tz.getID());
quartzJobList.add(new QuartzJob(jobName, jobGroup, dateTime.withZone(DateTimeZone.forID("Asia/Kathmandu")).toDate()));
}
}
}
好吧,这也有效,但是当我在网页中查看它时,我看到错误或不同的下一次触发时间。我尝试使用 joda time 转换为我的当地时间。我错过了什么?
**
我在控制台中打印了正确的时间:INFO: The date2013-08-20T07:10:00.000+05:45
**