定时任务类:使用@Scheduled注解设计定时任务

调用service层的方法,设置定时执行。

  • 定时任务类( @Scheduled )
@Component
@Log4j2
public class XXXScheduledClass {
    @Autowired
    private XXXService xxxService;
    @Scheduled(cron = "0 0/1 * * * ? ")
    //一分钟执行一次
    public void xxxMethod(){
        try {
            log.info("start:{}", DateUtil.now());
            xxxService.get();
        }catch (Exception e){
            e.printStackTrace();
            log.info("end:{}", DateUtil.now());
        }
    }
}
  • 启动类( @EnableScheduling )
@SpringBootApplication
@EnableScheduling
public class StartApplication {
    public static void main(String[] args) {
        SpringApplication.run(StartApplication .class, args);
    }
}

相关推荐

  1. 定时任务使用@Scheduled注解设计定时任务

    2024-07-16 23:52:03       19 阅读
  2. 使用Spring Boot整合定时任务Schedule

    2024-07-16 23:52:03       34 阅读
  3. @Scheduled注解创建定时任务的 3 种模式

    2024-07-16 23:52:03       27 阅读
  4. python自动定时任务schedule库的使用方法

    2024-07-16 23:52:03       48 阅读
  5. 【Spring Boot 3】【@Scheduled】静态定时任务

    2024-07-16 23:52:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-16 23:52:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 23:52:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 23:52:03       58 阅读
  4. Python语言-面向对象

    2024-07-16 23:52:03       69 阅读

热门阅读

  1. python 语法学习 day 7

    2024-07-16 23:52:03       26 阅读
  2. 搜维尔科技:Varjo XR-4开箱测评,里面都有啥?

    2024-07-16 23:52:03       16 阅读
  3. 开放开源开先河(一)

    2024-07-16 23:52:03       21 阅读
  4. 动态规划算法专题四--两个数组dp问题

    2024-07-16 23:52:03       20 阅读
  5. 如何检查对象中键是否存在?

    2024-07-16 23:52:03       22 阅读
  6. 【嵌入式】面试笔试问题整理 (持续更新)

    2024-07-16 23:52:03       22 阅读