使用方式
代码如下(示例):
@EnableScheduling
//开启异步事件的支持
@EnableAsync
@Component
public class TestTasK {
private static final Logger logger = LoggerFactory.getLogger(TestTasK.class);
// 异步执行
@Async
@Scheduled(cron = "0/1 * * * * ?")
public void test(){
String printTime = new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date());
logger.info("date: {}", printTime);
}
}