问题
I have a Scheduler with number of jobs. I want to be able to show all of the active jobs that are in the scheduler, by that I mean that i want to show when each job is triggerd. This is my code:
sched.start();
JobDetail job = newJob(Jobs.class)
.withIdentity(job_name_, "default")
.usingJobData("job_type", job_type_)
.build();
Trigger trigger = newTrigger()
.withIdentity(job_name_, "default")
.startNow()
.withSchedule(cronSchedule(date_time_))
.build();
sched.scheduleJob(job, trigger);
How can this be done? how do i get the cron expression from the trigger of the job ? also is there a way to see the cron expression as a date or somthing more detailed then the expression itself?
Any help will be appritiated,
Thank's In Advance.
回答1:
All the API is out there:
Trigger t = scheduler.getTrigger(new TriggerKey(job_name_, "default"))
The returned Trigger
class has getNextFireTime()
. Subclass it to get CRON expression:
((CronTrigger)t).getCronExpression();
The Scheduler has all the other methods you need:
getTriggerKeys()
getJobKeys()
getTriggersOfJob()
来源:https://stackoverflow.com/questions/9699323/java-quartz-get-all-details-from-a-scheduled-job