Reputation: 3728
I am using quartz scheduler ,it's working fine. I have following cron job:
<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>
Now, I have fired the job every one minute starting from now.(Correct me if I am wrong.). Well, Now I want to show all jobs in quartz scheduler and my code is:
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()));
}
}
}
Well, this works too but when I view it in web page I see wrong or different next fire time. I tried it with joda time to convert to my local time. What have I missed?
**
I get correct time printed in console though:INFO: The date2013-08-20T07:10:00.000+05:45
**
Upvotes: 1
Views: 1925
Reputation: 3728
Okay here is what I did finally. I converted the datetime to string format and the used it in JFS view.
DateTime dateTime = date == null ? null : new DateTime(triggers.get(0).getNextFireTime());
if (dateTime != null) {
quartzJobList.add(new QuartzJob(jobName, jobGroup, dateTime.toString("MM/dd/yyyy hh:mm:ss")));
}
Upvotes: 1