SpringBoot之Scheduling Tasks
来源:互联网 发布:专业淘宝图片拍摄价格 编辑:程序博客网 时间:2024/05/16 08:03
设置计划任务。
1 配置Scheduling Tasks
package sckeduling.tasks.hello;import java.text.SimpleDateFormat;import java.util.Date;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;@Componentpublic class SckeduledTasks { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 5000) public void reportCurrentTime(){ System.out.println("The time is now " + dateFormat.format(new Date())); }}
说明
The Scheduled annotation defines when a particular method runs. NOTE: This example uses fixedRate, which specifies the interval between method invocations measured from the start time of each invocation. There are other options, like fixedDelay, which specifies the interval between invocations measured from the completion of the task. You can also use @Scheduled(cron=”…”) expressions for more sophisticated task scheduling.
2 启动project
package sckeduling.tasks.hello;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.scheduling.annotation.EnableScheduling;@SpringBootApplication@EnableSchedulingpublic class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class); }}
说明
@EnableScheduling ensures that a background task executor is created. Without it, nothing gets scheduled.
0 0
- SpringBoot之Scheduling Tasks
- Scheduling Tasks
- SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)
- SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)
- SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)
- SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)
- Spring Boot 之 Scheduling Tasks定时任务
- SpringBoot之Scheduling(P)
- 11.1. Scheduling Tasks
- 构建一个Scheduling Tasks
- springcloud初学者--Scheduling Tasks
- Scheduling Tasks定时任务
- 【译】Scheduling Tasks
- spring boot:Scheduling Tasks
- Spring任务调度Scheduling Tasks
- spring - Scheduling Tasks 计划任务
- Spring任务调度Scheduling Tasks
- Scheduling R Tasks via Windows Task Scheduler
- Android 照片选择器
- 第六章、SpringMVC-注解式控制器详解-SpringMVC强大的数据绑定(2)
- 适配器getView 方法报了空指针
- android.os.Process.killProcess(android.os.Process.myPid())与Activity生命周期的影响
- MyEclipse把数据库中的表生成java实体类--利用Hibernate
- SpringBoot之Scheduling Tasks
- 02智力题
- 连接池
- 删除宽字符串
- MVC4数据注解和验证
- iOS 如何在一个存在多个project的workspace中引入cocoapods管理第三方类库
- 【CodeForces】597A - Divisibility(容斥原理,数学)
- H5无插件范式
- 关于VMware克隆的linux虚拟机eth0网卡无法正常启动的问题