java quartz get all details from a scheduled job
10,584
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:
Author by
user590586
Updated on June 13, 2022Comments
-
user590586 almost 2 years
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.
-
user590586 about 12 yearsthank's!! I can see the cron expression now.. is there a way to get the details of it like getHour\getDay\etc. ?
-
Tomasz Nurkiewicz about 12 years@user590586: do you mean get the day/hourt out of
Date
or from CRON expression? The former is achievable usingCalendar
, the latter - you have to parse CRON expression. Quartz has some utilities to do that. -
user590586 about 12 yearssorry 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! -
Tomasz Nurkiewicz about 12 years@user590586:
new org.quartz.CronExpression("0 0 12 * * ?")
- and it'll parse CRON expression for you. -
user590586 about 12 yearscan 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?
-
Tomasz Nurkiewicz about 12 years@user590586: you're right, the API of that class isn't particularly useful. There is a
protected
methodgetSet()
which returns all the information you need in a bit obscure way. Just subclassCronExpression
and alleviate it topublic
. 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. -
user590586 about 12 yearsthank's, I wrote a new question regarding this issue - stackoverflow.com/questions/9702412/…