How to make @Schedule method to be called only once at a time

假如想象 提交于 2021-02-10 04:34:05

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/8164176/how-to-make-schedule-method-to-be-called-only-once-at-a-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!