美文网首页
SpringTask

SpringTask

作者: dwwl | 来源:发表于2019-04-03 14:30 被阅读0次

任务调度 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

相关文章

  • SpringTask

    项目有定时任务的需求,对比了Timer、Quartz和SpringTask之后使用了SpringTask来配置定时...

  • SpringTask

    任务调度 SpringTask 常见的任务框架有Quartz和SpringTask,注意Cron表达式在者两种框...

  • SpringTimer

    依赖的jar包 JavaTimer (原生的方式) 基于spring的timer SpringTask TestM...

  • 定时任务

    SpringTask 使用 在SpringBoot的引导类上加开启定时任务的注解@EnableScheduling...

  • springtask定时发送邮件

    springtask定时发送邮件 开启设置 按照 打开QQ邮箱->设置->开启服务POP3/SMTP开启->获取...

  • SpringTask任务案例源码实现

    前言 一般来说,无论是生活中或者项目中都会用到定时任务。比如我自己来说,每天晚上写一篇博客,当然这个任务的时间点可...

  • springboot2.x | 定时任务

    简介:基与 springTask进行定时任务 1.启动类添加注解 2.定义一个scheduled服务 3.@sch...

  • Spring Task的坑

    背景:因用到定时任务,选了简单的springTask,使用中发现Task被执行两次。 解决方案:参考了几篇博文:这...

  • 运用SpringTask方式定时发送邮件

    1.首先配置QQ邮箱->设置->账户->开启服务POP3/SMTP开启->获取授权码image.png 2.添加p...

  • SpringTask定时任务实例

    在对比几种做法之后,找到了一种较容易的设置定时任务的方式 1.定时任务注解@EnableScheduling 在启...

网友评论

      本文标题:SpringTask

      本文链接:https://www.haomeiwen.com/subject/wyfzbqtx.html