Java Spring @Scheduled tasks executing twice

前端 未结 23 1661
清歌不尽
清歌不尽 2020-11-29 09:07

I have a simple test method here that is set to run every 5 seconds and it does, but looking at the System.out you can see it appears to be doing something odd.



        
23条回答
  •  既然无缘
    2020-11-29 09:28

    If you look at the documentation, there is a note that explicitly calls out this phenomenon.

    The note is under section 25.5.1 at this link, and reads:

    Make sure that you are not initializing multiple instances of the same @Scheduled annotation class at runtime, unless you do want to schedule callbacks to each such instance. Related to this, make sure that you do not use @Configurable on bean classes which are annotated with @Scheduled and registered as regular Spring beans with the container: You would get double initialization otherwise, once through the container and once through the @Configurable aspect, with the consequence of each @Scheduled method being invoked twice.

    I understand that this is merely suggestion at this point, but I do not think we have enough information to diagnose the issue further.

提交回复
热议问题