任务调度 SpringTask
常见的任务框架有Quartz和SpringTask,注意Cron表达式在者两种框架上的区别
SpringTask支支持6个域 不支持LW
SpringTask Demo
配置文件
applicationContext-task.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd">
<context:component-scan base-package="com.pinyougou.task"/>
<task:annotation-driven/>
</beans>
SeckillTask.java
@Component
public class SeckillTask {
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private TbSeckillGoodsMapper seckillGoodsMapper;
@Scheduled(cron="0 * * * * ?")
public void refreshSeckillGoods(){
System.out.println("执行了秒杀商品增量更新 任务调度"+new Date());
}
Cron表达式
注意两个特殊的域DayofMonth DayofWeek 两者必须有一个不指定数值 即 ?,因为两者会产生冲突,
SpringTask不支持第一种
1.png 2.png 3.png 4.png 5png.png 6.png 7.png
网友评论