Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now