如何使@Schedule方法一次仅被调用一次 [英] How to make @Schedule method to be called only once at a time

查看:543
本文介绍了如何使@Schedule方法一次仅被调用一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆