WANG LH , Research & Development

Spring 定时任务

2021.05.31 22:05

# 开启定时任务

xml
    <task:executor id="asyncTask" pool-size="20" />   
    <task:annotation-driven executor="asyncTask" />
注解
    @EnableScheduling

Demo

每隔 n 分钟执行一次

// 每隔5分钟执行一次
@Scheduled(cron = "0 0/5 * * * ?")

定点执行任务

// 每天3点、15点执行一次任务
@Scheduled(cron = "0 0 3,15 * * ? ")