这一篇我们来介绍定时器
像是淘宝下单+未付款:淘宝需要将超过24小时未付款的订单“自动”关闭。淘宝收货+不点“确认收货”:7天”自动“确认收货。
淘宝订单已完成+不评价:”自动“好评。
等都是运用了定时器
1.添加约束
在applicationContext.xml里面添加关于task的约束。
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.3.xsd
<!-- 放开定时任务配置 -->
<task:annotation-driven/>
2.建立一个新的包名字叫job,并在里面建立一个新的类,TaskJob。
在里面添加一个方法,并为其写上注解
@Scheduled(cron="0/10 * * * * ?")
public void userGrade(){
System.out.println("定时器执行时间:" + DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
}
运行之后&#