java quartz get all details from a scheduled job

user590586 picture user590586 · Mar 14, 2012 · Viewed 10.4k times · Source

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.

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Mar 14, 2012

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: