views:

477

answers:

2

I have a simple quartz trigger running in Spring 2.5.6-SEC01.

Trigger definition looks like this:

<bean id="AdvicesCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="AdvicesQuartzJob"/>
    <property name="cronExpression" value="0 20/15 * * * ?"/>
</bean>

This is my scheduler factory:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
        <ref bean="AdvicesCronTrigger"/>
        </list>
    </property>
</bean>

I've read this documentation about firing CRON triggers from Quartz. This is an excerpt:

CronTrigger Example 1 - an expression to create a trigger that simply fires every 5 minutes

"0 0/5 * * * ?"

Today I fired my program at 9:40. This is my execution output:

Edit: Bobby is right in his appreciation. I've updatted my execution log:

2010-02-11 09:50:00,000 INFO - START

2010-02-11 10:20:00,000 INFO - START

2010-02-11 10:35:00,000 INFO - START

2010-02-11 10:50:00,000 INFO - START

2010-02-11 11:20:00,000 INFO - START

2010-02-11 11:35:00,000 INFO - START

I expected that this trigger will be fired at

9:50

10:05

10:20

10:35

...

How to accomplish this? Which CRON expression use?

+1  A: 

The 20/15 part of the cron expression means every 15 minutes after the 20'th minute of the hour. This means that it will always start at the 20'th minute.

I have never tested it but maybe an expression like this one would be what you are searching for :
0 */15 * * * ?

Bobby
Why then Quartz fires my trigger at 9:50 after executen the app at 9:40?
SourceRebels
Because I think it translates the 20/15 expression in a 20,35,50 expression.
Bobby
Problem is, I have some (2 for now) quartz triggers and I don't want this to be triggered at same time that other triggers but I want same periodicity for all. I wrote 10/15 on first, 20/15 on second trigger.
SourceRebels
Then would it be that bad to just write the exact minutes you want them to be triggered? Also you could control this by setting one at second 0 and the other one at second 30.
Bobby
+1  A: 

Not to give you a non-related answer, but sometimes it makes sense to use some services instead of trying to do it yourself :) Take a look at http://www.cronservice.co.uk/new/, http://scheduler.codeeffects.com, or http://www.webbasedcron.com/

Jane
Thank you very much :-)
SourceRebels