如何使@Schedule方法一次仅被调用一次 [英] How to make @Schedule method to be called only once at a time
问题描述
我们正在使用@Schedule
EJB批注来开始计划的作业,每x秒执行一次增量SOLR导入.当然,我们希望索引中的时移尽可能少.目前,我尝试每5秒执行一次增量操作.
We are using the @Schedule
EJB annotation to start a scheduled job do a delta SOLR import every x seconds. Of course we want to have as less timeshift in indexing as possible. Currently I try to do the delta every 5 seconds.
所以我的问题是:我可以确保该工作仅被调用一次吗? 因此,假设索引的持续时间超过5秒,下一个计划会一直等到前一个计划恢复运行吗?
So my question is: Can I make sure the job is only called once? So let's say the indexing is lasting longer than 5 seconds, will the next schedules call wait until the previous is coming back?
推荐答案
是.您可以将Bean设为@Singleton
并使用 @Lock(LockType.Write)
,以确保计时器不会并行运行.请注意,LockType.Write
是Singleton中的默认设置.因此,甚至不需要带有注释的明确提及.
Yes. You can make the bean a @Singleton
and use @Lock(LockType.Write)
to make sure that timers don't run in parallel. Note that LockType.Write
is the default in a Singleton. So even the explicit mention with the annotation would not be required.
这篇关于如何使@Schedule方法一次仅被调用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!