springboot整合定时任务task
下面是例子:
1. //开启定时任务:
@enablescheduling
public class demoapplication {
2./**
* 定时任务:
*/
@component
public class testtask {
private static final simpledateformat dataformat = new simpledateformat("hh:mm:ss");
//定义每3秒执行任务:
@scheduled(fixedrate = 3000)
public void reportcurrenttime(){
system.out.println("现在时间:" + dataformat.format(new date()));
}
}
3.启动就完事了.
提示: 定时任务可以用cron表达式:@scheduled(cron = "")
如对本文有疑问, 点击进行留言回复!!
Flink程序JDK8 运行一段时间后NullException解决
解决: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
SpringBoot中定制异常页面(404页面配置提高用户体验)
DataGrip和IDEA无法连接上Mysql问题解决方法详解
Java基础语法(多态、类、接口、Date类、基本类型、系统类)
网友评论