Scheduling Task in Spring/Java

前端 未结 5 1548
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 13:07

I am spawning a thread which will keep pulling the chunk of records from database and putting them into the queue. This thread will be started on the server load. I want thi

5条回答
  •  一整个雨季
    2021-01-05 13:47

    You can use the @Scheduled annotation to run jobs. First create a class with a method that is annotated with @Scheduled.

    Class

    public class GitHubJob {
    
       @Scheduled(fixedDelay = 604800000)
       public void perform() {
          //do Something
        }
    }
    

    Then register this class in your configuration files.

    spring-context.xml

    
    
    
    
    
    
    
    
    
    
    

    For more about scheduling visit the Spring Docs.

提交回复
热议问题