Solved

Quartz Scheduler - How to get cron expression given job name and group name?

Posted on 2010-09-03
4
1,132 Views
Last Modified: 2012-06-27
Hi,

I'm using Quartz Scheduler v.1.8.0.

How do I get the cron expression which was assigned/attached to a Job and scheduled using CronTrigger?  I have the job name and group name in this case.  Though many Triggers can point to the same Job, in my case it is only one.

There is a method available in Scheduler class, Scheduler.getTriggersOfJob(jobName, groupName), but it returns only Trigger array.

NOTE: Class CronTrigger extends Trigger
0
Comment
Question by:Zoniac
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
gremwell earned 100 total points
ID: 33602377
If there only one trigger per job, I would expect the array returned by getTriggersOfJob() contain one entry only. You can probably cast it (the first element of the array, not the array itself) to CronTrigger and invoke CronTrigger's getCronExpression() method.
0
 
LVL 1

Author Comment

by:Zoniac
ID: 33602559
> I would expect the array returned by getTriggersOfJob() contain one entry only

Yes, you're right.  In my case, it is only one trigger per job.
0
 
LVL 1

Author Comment

by:Zoniac
ID: 33602565
> You can probably cast it (the first element of the array, not the array  itself) to CronTrigger and invoke CronTrigger's getCronExpression()  method.

Yes, it works.

Code example shown below:

Trigger[] triggers = scheduler.getTriggersOfJob(jobName, groupName);
for (Trigger trigger : triggers) {
    if (trigger instanceof CronTrigger) {
        CronTrigger cronTrigger = (CronTrigger) trigger;
        String cronExpr = cronTrigger.getCronExpression();
    }
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:Zoniac
ID: 33602631
Solution arrived.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question