如何在特定的时间段内重复执行一个cronExpression?
问候大家 我有一个 cronExpression,我希望它在应用程序启动时启动并每秒重复一次,我通过 xml 配置定义 cronExpression,如下所示:
<bean id="myCronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="myJob" />
<property name="cronExpression" >
<value>${first.trigger.time}</value>
</property>
</bean>
有什么帮助吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(也许
* * * * ?
* 也可以)@see: http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html
每秒都会触发一次。
如果您需要 1 秒的固定延迟而不是每秒触发一次,那么您可以使用 Spring 3.0 注释:
@Scheduled(fixedRate=1000)
@see: http://static.springsource.org/spring/docs/3.0.x/reference/scheduling.html
顺便说一句:您可以使用
@Scheduled(cron="*/1 * * * * MON-FRI")
注释,而不是 XML 配置。(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.您还可以使用更适合您用途的 SimpleTrigger。
来自SimpleTrigger 课程:
You can also use a SimpleTrigger which is more suited for your usage.
From the SimpleTrigger lesson: