81,094
社区成员
发帖
与我相关
我的任务
分享
<task:scheduler id="scheduler" pool-size="10" />
<task:executor id="executor" keep-alive="3600" pool-size="100-200"
queue-capacity="500" rejection-policy="CALLER_RUNS" />
<task:annotation-driven executor="executor" scheduler="scheduler" />
然后,你就可以在你的类里用@Scheduled注解来做定时任务了[/quote]
我现在的情况属于偷了个懒 没有做任何配置,直接使用的@Scheduled[/quote]能跑任务就OK了<task:scheduler id="scheduler" pool-size="10" />
<task:executor id="executor" keep-alive="3600" pool-size="100-200"
queue-capacity="500" rejection-policy="CALLER_RUNS" />
<task:annotation-driven executor="executor" scheduler="scheduler" />
然后,你就可以在你的类里用@Scheduled注解来做定时任务了[/quote]
我现在的情况属于偷了个懒 没有做任何配置,直接使用的@Scheduled<task:scheduler id="scheduler" pool-size="10" />
<task:executor id="executor" keep-alive="3600" pool-size="100-200"
queue-capacity="500" rejection-policy="CALLER_RUNS" />
<task:annotation-driven executor="executor" scheduler="scheduler" />
然后,你就可以在你的类里用@Scheduled注解来做定时任务了@Component
public class Job {
@Scheduled(cron="0 0/1 * * * ?")//一分钟更新一次
public void test0(){
System.out.println("test0->"+new Date());
}
@Scheduled(cron="0/30 * * * * ?")//30秒更新一次
public void test1(){
System.out.println("test1->"+new Date());
}
@Scheduled(fixedDelay=30000)
public void test2(){
System.out.println("test2->doing fixedDelay->"+new Date());
}
@Scheduled(fixedRate=5000)
public void test3(){
System.out.println("test3->doing fixedRate->"+new Date());
}
@Scheduled(cron="0/5 * * * * ?", initialDelay=1000)
public void test4(){
System.out.println("test4->doing initialDelay->"+new Date());
}
}
spring-*.xml
<task:scheduler id="scheduler" pool-size="10" />
<task:executor id="executor" keep-alive="3600" pool-size="100-200"
queue-capacity="500" rejection-policy="CALLER_RUNS" />
<task:annotation-driven executor="executor" scheduler="scheduler" />