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编程之定时任务的更多相关文章

  1. SpringBoot中的定时任务与Quartz的整合

    SpringBoot集成Quartz 定时任务Quartz : 就是在指定的时间执行一次或者循环执行,在项目的开发中有时候会需要的, 还是很有用的. SpringBoot内置的定时 添加依赖 < ...

  2. SpringBoot几种定时任务的实现方式

    定时任务实现的几种方式: Timer:这是java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行, ...

  3. springBoot中的定时任务

    springBoot中的定时任务 1:在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 2:新建ScheduledTasks任务类 : package c ...

  4. SpringBoot中执行定时任务

    一:在SpringBoot中使用定时任务相当的简单.首先,我们在启动类中加入@EnableScheduling来开启定时任务. @SpringBootApplication @EnableSchedu ...

  5. springboot编程之全局异常捕获

    springboot编程之全局异常捕获 1.创建GlobalExceptionHandler.java,在类上注解@ControllerAdvice, 在方法上注解@ExceptionHandler( ...

  6. springboot整合@Scheduled定时任务的使用

    1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...

  7. SpringBoot系列——动态定时任务

    前言 定时器是我们项目中经常会用到的,SpringBoot使用@Scheduled注解可以快速启用一个简单的定时器(详情请看我们之前的博客<SpringBoot系列--定时器>),然而这种 ...

  8. Springboot的默认定时任务——Scheduled注解

    本博客参考博文地址. 1.pom依赖: 引入springboot starter包即可 <dependencies> <dependency> <groupId>o ...

  9. 在SpringBoot中配置定时任务

    前言 之前在spring中使用过定时任务,使用注解的方式配置很方便,在SpringBoot中的配置基本相同,只是原来在spring中的xml文件的一些配置需要改变,在SpringBoot中也非常简单. ...

随机推荐

  1. mssql占用80端口解决办法

    services.msc

  2. selenium测试(Java)-- 键盘事件(七)

    1 package com.test.key; 2 3 import org.openqa.selenium.By; 4 import org.openqa.selenium.Keys; 5 impo ...

  3. R语言低级绘图函数-abline

    abline 函数的作用是在一张图表上添加直线, 可以是一条斜线,通过x或y轴的交点和斜率来确定位置:也可以是一条水平或者垂直的线,只需要指定与x轴或y轴交点的位置就可以了 常见用法: 1)添加直线 ...

  4. vnc 多用户登录

    1, 创建新用户: $ useradd tom $ passwd tom 2,  登录到tom账户,创建vnc实例: $ su tom$ vncserver 这时可以看看~/.vnc/目录下,有一些如 ...

  5. linux下常用FTP命令 1. 连接ftp服务器

    1. 连接ftp服务器 格式:ftp [hostname| ip-address] a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密 ...

  6. 访问GitLab的PostgreSQL数据库

    1.登陆gitlab的安装服务查看配置文件 cat /var/opt/gitlab/gitlab-rails/etc/database.yml production: adapter: postgre ...

  7. Davlik虚拟机

    过几天得去面试,感觉原来做的东西都忘了. 有点累,无意看了下二师兄的小论文,想来原先自己也参与过一点点,所以记录下: Dalvik虚拟机中共有3种解释器,分别时SWITCH_INTERP,THREAD ...

  8. LR通用的性能分析流程

    Step1:从分析Summary的事务执行情况入手Summary主要是判定事务的响应时间与执行情况是否合理.如果发现问题,则需要做进一步分析.通常情况下,如果事务执行情况失败或响应时间过长等,都需要做 ...

  9. mysql 异常 Lock wait timeout exceeded; try restarting transaction;expc=java.sql.SQLExcept

    这种一般是等锁超时了,可以设置延长等锁时间. mysql> set innodb_lock_wait_timeout=100 Query OK, 0 rows affected (0.02 se ...

  10. 换个思路理解Javascript中的this

    https://segmentfault.com/a/1190000010328752