Springboot定時任務(1)

2021-10-11 03:52:49 字數 684 閱讀 9596

在springboot中使用定時定時任務可以說是一種享受

不需要引入其他的依賴,springboot框架的預設依賴就足以滿足

org.springframework.boot

spring-boot-starter-parent

2.4.0

在啟動類上需要加入@enablescheduling註解,然後在需要定時執行的方法上面加上@scheduled註解,常用引數型別如下

@scheduled(cron = "0/5 * * * * ?")

public void test() catch (interruptedexception e)

}

執行結果

@scheduled(fixeddelay = 5000)

public void test1() catch (interruptedexception e)

}

執行結果:

@scheduled(fixedrate = 5000)

public void test1() catch (interruptedexception e)

}

執行結果

SpringBoot 定時任務

第一步 在啟動類中加入如下註解 enablescheduling public class public static void main string args 注意 enablescheduling必須加,否則無法開啟定時任務 第二步 建立定時任務 component public class ...

Spring boot定時任務

最近做專案,需要使用定時任務,半個小時去更新redis資料,於是便學習了一下經驗。希望可以幫到你們。定時任務可使用三種 created by fx on 2017 9 4.component allargsconstructor public class featuredatatask 實現乙個任務...

Spring boot 定時任務

1.在啟動類上加 enablescheduling註解 package com.example.demo import org.springframework.scheduling.annotation.enablescheduling enablescheduling public static ...