一、@Scheduled 注解
//定时任务类
@Slf4j //日志注解
@Service
public class ScheduleTaskService {
private static final Logger log = LoggerFactory.getLogger(ScheduleTaskService.class);
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(fixedRate = 5000)
public void reportCurrentTime(){
log.info("每五秒执行一次 : {}",dateFormat.format(new Date()));
}
@Scheduled(cron = "0 13 15 ? * *")
public void fixTimeExecute(){
log.info("指定时间执行 : {}",dateFormat.format(new Date()));
}
}
//配置类
@Configuration
@ComponentScan("com.how2java.tmall.scheduletask")
@EnableScheduling //开启定时任务注解 //2
public class ScheduleTaskConfig {
}