zoukankan      html  css  js  c++  java
  • java spring boot 定时器

    java spring boot 定时器

    启动类加个

    @EnableScheduling

    package com.example.demo2122;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.scheduling.annotation.EnableScheduling;
    
    @SpringBootApplication
    @EnableScheduling
    public class Demo2122Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Demo2122Application.class, args);
        }
    
    
    
    
    }


    然后函数前面加个
     @Scheduled(fixedRate = 5000)


    package com.example.demo2122;
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    import javax.annotation.Resource;
    
    import java.util.*;
    @RestController
    @Component
    public class HelloControl {
    
        @GetMapping("/hello")
        public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
    
    
            return "fwef";
        }
        @Scheduled(fixedRate = 5000)
        public void scheduledTask1(){
            System.out.println("5秒执行一次");
        }
    
    
    }

    然后。就跑起来了。。。 

  • 相关阅读:
    0317复利计算的回顾与总结
    0518 Scrum 项目 5.0
    0517 Scrum 项目4.0
    0512 Scrum 项目3.0
    实验三 进程调度模拟程序
    0505 Scrum 项目1.0
    0502团队项目 SCRUM团队成立
    0428 团队项目2.0
    0422团队项目
    实验二 作业调度模拟程序
  • 原文地址:https://www.cnblogs.com/newmiracle/p/12750400.html
Copyright © 2011-2022 走看看