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秒执行一次");
        }
    
    
    }

    然后。就跑起来了。。。 

  • 相关阅读:
    关于类型转换构造函数的疑惑点
    类模板与静态 成员变量
    模板与友元
    类模板与派生
    类模板
    函数模板
    泛型程序设计基本概念
    3、成员函数
    条款 06:若不想使用编译器自动生成的函数,就该明确拒绝
    PHP操作redis
  • 原文地址:https://www.cnblogs.com/newmiracle/p/12750400.html
Copyright © 2011-2022 走看看