2

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.

STW
  • 44,917
  • 17
  • 105
  • 161
user590586
  • 2,960
  • 16
  • 63
  • 96

1 Answers1

7

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:

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • thank's!! I can see the cron expression now.. is there a way to get the details of it like getHour\getDay\etc. ? – user590586 Mar 14 '12 at 10:07
  • @user590586: do you mean get the day/hourt out of `Date` or from CRON expression? The former is achievable using `Calendar`, the latter - you have to parse CRON expression. Quartz has some utilities to do that. – Tomasz Nurkiewicz Mar 14 '12 at 10:10
  • sorry but i didn't quit understood, I want to get from the cron expression all the details about it's triggring time - which days of the week, what hour, etc.. should i parse the CRON expression to `calendar` ? and then get the info i want? is this what you meant? if so, is there an example or api for the parsing method ? thank's again! – user590586 Mar 14 '12 at 10:28
  • @user590586: `new org.quartz.CronExpression("0 0 12 * * ?")` - and it'll parse CRON expression for you. – Tomasz Nurkiewicz Mar 14 '12 at 12:00
  • can i get the info i want from the new CronExpression object? from what i see i can't get the hour,days,etc.. how do i get all the details from this object? – user590586 Mar 14 '12 at 12:21
  • @user590586: you're right, the API of that class isn't particularly useful. There is a `protected` method `getSet()` which returns all the information you need in a bit obscure way. Just subclass `CronExpression` and alleviate it to `public`. Also if you have further questions, please ask another question as this discussion is growing too long. Add a link here so I can follow-up. – Tomasz Nurkiewicz Mar 14 '12 at 12:28
  • thank's, I wrote a new question regarding this issue - http://stackoverflow.com/questions/9702412/quartz-cronexpression-get-all-expression-parameters-info – user590586 Mar 14 '12 at 12:57