问题描述
我们使用 @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
是单例中的默认值.因此,甚至不需要使用注释明确提及.
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 方法一次只调用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!