170627、springboot编程之定时任务
springboot定时任务,比较简单!
1、编写DemoSchedule.java类
package com.rick.common.schedule; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import java.text.SimpleDateFormat;
import java.util.Calendar; /**
* Desc : 定时任务
* User : RICK
* Time : 2017/8/21 21:16
*/
@Configuration
@EnableScheduling
public class DemoSchedule { //cron表达式 秒分时 日月周 年
@Scheduled(cron = "0/10 * * * * ?") //每10秒执行一次
public void demoPrint(){
System.out.println("现在时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
}
}
2、启动项目测试
3、项目清单
170627、springboot编程之定时任务的更多相关文章
- SpringBoot中的定时任务与Quartz的整合
SpringBoot集成Quartz 定时任务Quartz : 就是在指定的时间执行一次或者循环执行,在项目的开发中有时候会需要的, 还是很有用的. SpringBoot内置的定时 添加依赖 < ...
- SpringBoot几种定时任务的实现方式
定时任务实现的几种方式: Timer:这是java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行, ...
- springBoot中的定时任务
springBoot中的定时任务 1:在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 2:新建ScheduledTasks任务类 : package c ...
- SpringBoot中执行定时任务
一:在SpringBoot中使用定时任务相当的简单.首先,我们在启动类中加入@EnableScheduling来开启定时任务. @SpringBootApplication @EnableSchedu ...
- springboot编程之全局异常捕获
springboot编程之全局异常捕获 1.创建GlobalExceptionHandler.java,在类上注解@ControllerAdvice, 在方法上注解@ExceptionHandler( ...
- springboot整合@Scheduled定时任务的使用
1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...
- SpringBoot系列——动态定时任务
前言 定时器是我们项目中经常会用到的,SpringBoot使用@Scheduled注解可以快速启用一个简单的定时器(详情请看我们之前的博客<SpringBoot系列--定时器>),然而这种 ...
- Springboot的默认定时任务——Scheduled注解
本博客参考博文地址. 1.pom依赖: 引入springboot starter包即可 <dependencies> <dependency> <groupId>o ...
- 在SpringBoot中配置定时任务
前言 之前在spring中使用过定时任务,使用注解的方式配置很方便,在SpringBoot中的配置基本相同,只是原来在spring中的xml文件的一些配置需要改变,在SpringBoot中也非常简单. ...
随机推荐
- 关于在Android中添加事件监听器的方法
一.匿名内部类 1.先找到那个控件(初始化) private Button bt1; //onCreate方法外 bt1 = (Button)findViewById(R.id.button1); ...
- Linux之zip压缩
1.压缩 对于test目录,使用 zip -rq test.zip test r表示递归压缩,q表示不显示过程 2.解压缩 unzip -q test.zip
- linux -- 查看Ubuntu命令行调用的文件
which 如: 输入:which reboot 输出:/sbin/reboot 输入:which shutdown -h now 输出:/sbin/shutdown
- CentOS下rpm指令和yum指令详解
centos的软件安装大致可以分为两种类型: [centos]rpm文件安装,使用rpm指令 类似[ubuntu]deb文件安装,使用dpkg指令 [centos]yum安装 类似[ubuntu]ap ...
- 记录下Lambda常用的表现形式
纯粹记录下Lambda的表现形式: (x, y) => x * y;//多参数,隐式类型=>表达式 x => x * ;//单参数,隐式类型=>表达式 x => { ; ...
- oracle最精简客户端(3个文件+1个path变量就搞定oracle客户端)
oracle最精简客户端: network\admin\tnsnames.ora (自己新建)oci.dlloraocieill.dll 将oci.dll的路径加到path变量中就可以了 tnsnam ...
- MQTT--单片机实现即时通信
链接--->http://blog.csdn.net/zhou6343178/article/details/51182623 1.准备条件: a)硬件:ATMEGA644PA 8位单片机 EN ...
- 如何在HTML中播放flash
随着html的风靡,改变了之前前端的许多条条框框,而video的出现使flash仿佛都要退出历史的舞台了,但是h5也会出现以下局限性,比如说,在一些不支持h5的浏览器上,此处省略一万只草泥马..... ...
- js二级联动
<body> <section> <a>省份</a> <select id="province"> <option ...
- 定义了一个UIImageView如何使加载的图片不会失真 UIImageView的Frame值是固定的
定义了一个UIImageView如何使加载的图片不会失真 UIImageView的Frame值是固定的 UIViewContentModeScaleToFill, 缩放内容到合适比例大小 UIVie ...