项目定时任务

1、在项目中,有时候我们需要定时的进行刷新、定时进行消息的方法;这个时候我们就可以通过一个定时任务去进行触发;可以通过设置时间进行触发

具体代码内容

package com.nd.job;

import java.time.LocalDateTime;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import lombok.extern.slf4j.Slf4j;

@Configuration // 1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j
public class TimeJob {
	
	
	
	@Scheduled(cron = "0/5 * * * * ?")
	// 或直接指定时间间隔,例如:5秒
	// @Scheduled(fixedRate=5000)
	public void configureTasks() {

//相应执行代码写在这一段内
	}

//如果有多重类型的定时任务,则直接多复制几个下来

@Scheduled(cron = "0/5 * * * * ?")
	// 或直接指定时间间隔,例如:5秒
	// @Scheduled(fixedRate=5000)
	public void configureTasks2() {

//相应执行代码写在这一段内
	}
}

这边最主要的就是需要有以下注解:

@Configuration // 1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j

注解:@Scheduled(cron = "0/5 * * * * ?"):则是代表着刷新的规则是怎么样:

https://help.aliyun.com/document_detail/64769.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值