Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with Quartz's Cron Expression  RSS feed

lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am using quartz as the scheduler for one of my application and using CronTrigger with CronExpression to schedule my jobs.
I had a scenario where I had a run a job and repeat it every time interval(say 40 min) on all days starting from the time it is triggered. So, I was using an expression like "0 0/40 * * * ?" .
However, now I am looking for a little different use case. I want to run and repeat a job between a start and end time window of the day. Suppose between 2.30 - 4.10 every day and repeats at an interval of 40 min.
i.e, trigger should get fired at 2.30, 3.10, 3.50
Can someone let me know if such a scenario can be achieved through cron expression in quartz?
I have gone through lots of docs and tutorials on quartz and cron expression but couldn't find a way of achieving this.

One thing that I seem to understand from the docs is that cron is only to trigger/fire a job at a particular min in every hour (like run a job at 5th min, 10th min etc. every hour or at 5th, 10th, 15th hour etc.) but you cannot use it start a job at a particular min in an hour and end at a different min in another hour. Is that true or can I do what I need using cron expressions?

One thought/workaround that I could think for my use case is to create three different triggers :
one for scheduling from 2.30-3.00(for the partial hour at start)
one for 3.00-4.00(for the full hours)
and one for 4.00-4.10( for the partial hour at end).
However, with these 3 triggers, it does not give the continuity in the intervals. i.e, the trigger would run at 2.30, again at 3.00 and 3.40 and at 4.00.
Instead of the 2.30, 3.10, 3.50 that I actually needed.

Any help is greatly appreciated . Thanks.

Posted it in quartz forums as well since that is dedicated to quartz .
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!