cron 触发器的计时器可以重置吗?
我知道我可以重置 Java 计时器,但是,由于我已经仅使用 cron 触发器完成了很多工作,我想知道是否可以重置触发器触发之前剩余的时间。
这里有更多细节:
- 在网站上,从数据库中随机选择一个事件并将其作为“精选”事件贴在首页上。
- 每三个小时,该事件就会被删除,并以新的特色事件重复该过程。
这就是 cron 触发器的用武之地。现在,我想添加一条额外的规则:
如果该事件的所有可用点都被占用,我希望该事件提前触发,立即与新的特色事件一起循环并恢复正常每三小时一次的模式。否则,售完的活动只会作为“特色”停留在首页上。
这可以做到吗?我在 tomcat 6 上使用 Java SpringSource 框架
。谢谢。
更新:在继续进行几次谷歌查询后,我终于从http://spacemapper.sourceforge.net/mn8/api/org/media/mn8/util/cron/CronTrigger.html。但这可以在Spring中实现吗?
这是一些代码,计时器当前未设置为 3 小时,仅用于测试:
<bean id="queueJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.---.-.service.scheduler.BaseQuartzScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="processorName" value="scheduleListingActions" />
<entry key="methodName" value="revolveQueue" />
</map>
</property>
</bean>
<bean id="queueCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="queueJob" />
<property name="cronExpression" value="1-59/59 * * * * ?" />
</bean>
I know I can reset the Java timer, but, since I already have so much work done using only a cron trigger, I wonder if it's possible to reset the amount of time left before the trigger fires.
Here's a bit more detail:
- On the website, an event is chosen randomly from the database and plastered on the front page as the "Featured" event.
- Every three hours, the event is removed and the process is repeated with a new featured event.
So that's where the cron trigger comes in. Now, I want to add an additional rule:
If all the available spots for that event are taken, I want that event to fire prematurely, revolving right away with a new featured event and resuming the normal every-three-hours pattern. Otherwise, a sold out event just lingers on the front page as "featured".
Can this be done? I'm using Java SpringSource framework on tomcat 6.
Thank you.
Update: after continuing a few more google queries, I finally came up with the "reset()" function from http://spacemapper.sourceforge.net/mn8/api/org/media/mn8/util/cron/CronTrigger.html. But could this be implemented in Spring?
Here is some code, the timer isn't set to 3 hours currently, only for testing:
<bean id="queueJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.---.-.service.scheduler.BaseQuartzScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="processorName" value="scheduleListingActions" />
<entry key="methodName" value="revolveQueue" />
</map>
</property>
</bean>
<bean id="queueCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="queueJob" />
<property name="cronExpression" value="1-59/59 * * * * ?" />
</bean>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
at
(它可以让您安排程序何时被调用)或者只编写一个休眠的守护进程。使用 cron 来达到这个目的是很混乱的。You can use
at
(which lets you schedule when a program will be called) or just write a daemon that sleeps. Using cron for this purpose is messy.