Mahmoud Saleh
Mahmoud Saleh

Reputation: 33605

How to repeat a cronExpression in a specific period of time?

greetings all I have a cronExpression that I want it to be started on application startup and repeated every second, I am defining cronExpression via xml configuration as follows:

<bean id="myCronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="myJob" /> 
        <property name="cronExpression" >
        <value>${first.trigger.time}</value> 
        </property>      
</bean>

any help please ?

Upvotes: 1

Views: 5706

Answers (2)

Kieren Dixon
Kieren Dixon

Reputation: 937

You can also use a SimpleTrigger which is more suited for your usage.

From the SimpleTrigger lesson:

SimpleTrigger should meet your scheduling needs if you need to have a job execute exactly once at a specific moment in time, or at a specific moment in time followed by repeats at a specific interval.

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="jobDetailBean" />
    <property name="repeatInterval" value="1000" />
</bean>

Upvotes: 1

Ralph
Ralph

Reputation: 120821

0/1 * * * ? *

(maybe * * * * ? * works too)

@see: http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html

This fires every second.

If you need an fixed delay of 1 second instead of firering every second, then you could use the Spring 3.0 annotations to: @Scheduled(fixedRate=1000)

@see: http://static.springsource.org/spring/docs/3.0.x/reference/scheduling.html

BTW: you could use the @Scheduled(cron="*/1 * * * * MON-FRI") annotation, instead of XML configuration.

Upvotes: 4

Related Questions