java quartz get all details from a scheduled job

心不动则不痛 提交于 2020-01-16 04:07:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!