`

@Scheduled

 
阅读更多

 

参考文档

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

 

命名空间

xmlns:task="http://www.springframework.org/schema/task"

 

注解定义

<task:annotation-driven scheduler="myScheduler"/>


<task:scheduler id="myScheduler" pool-size="10"/>

 

schedule应用

 

The @Scheduled annotation can be added to a method along with trigger metadata. For example, the following method would be invoked every 5 seconds with a fixed delay, meaning that the period will be measured from the completion time of each preceding invocation.

@Scheduled(fixedDelay=5000)
public void doSomething() {
    // something that should execute periodically
}

If a fixed rate execution is desired, simply change the property name specified within the annotation. The following would be executed every 5 seconds measured between the successive start times of each invocation.

@Scheduled(fixedRate=5000)
public void doSomething() {
    // something that should execute periodically
}

If simple periodic scheduling is not expressive enough, then a cron expression may be provided. For example, the following will only execute on weekdays.

@Scheduled(cron="*/5 * * * * MON-FRI")
public void doSomething() {
    // something that should execute on weekdays only
}

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics