Solved

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

Posted on 2010-09-03
4
1,124 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 108
Checkbox and ListView in Android Layout 4 67
servlet doXXX methods 3 49
ejb on wildfly 5 20
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

809 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