Solved

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

Posted on 2010-09-03
4
1,183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

728 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