spring定时任务详解

本文详细介绍了Spring框架中定时任务的配置,包括XML配置和注解方式。重点讲解了@Scheduled注解的fixedDelay和fixedRate属性,并深入探讨了Cron表达式的使用,提供了一个Cron表达式生成网站链接。通过示例展示了多种Cron表达式的实际应用,帮助读者理解和掌握Spring定时任务的灵活调度。
摘要由CSDN通过智能技术生成

spring定时任务详解

 

Spring配置文件xmlns加入

xmlns:task="http://www.springframework.org/schema/task"

xsi:schemaLocation中加入

http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"


Spring扫描注解的配置

<context:component-scan base-package="com.imwoniu.*" />

任务扫描注解

<task:executor id="executor" pool-size="5" /> 
<task:scheduler id="scheduler" pool-size="10" /> 
<task:annotation-driven executor="executor" scheduler="scheduler" />


代码实现:

注解@Scheduled 可以作为一个触发源添加到一个方法中,例如,以下的方法将以一个固定延迟时间5秒钟调用一次执行,这个周期是以上一个调用任务的完成时间为基准,在上一个任务完成之后,5s后再次执行:

@Scheduled(fixedDelay = 5000)
public vo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值