Spring 计划任务
来源:互联网 发布:如何下载ppt软件 编辑:程序博客网 时间:2024/06/01 07:49
/***@author StormMaybin*@date 2017-01-28*/
生命不息,奋斗不止!
Spring 定时任务介绍
从spring 3.1开始,计划任务在Spring中的实现变得异常的简单,首先通过类注解@EnableScheduing 来开启对计划任务的支持!然后在要执行的计划任务上面添加@Scheduled,声明这是一个计划任务!
计划执行类
ScheduledTaskService.java
package com.stormma.service;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Service;import java.text.SimpleDateFormat;import java.util.Date;/** * <p>Created by StormMa on 2017/1/28.</p> * * @author StormMa */@Servicepublic class ScheduledTaskService { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 5000) public void reportCurrentTime() { System.out.println("每隔五秒钟执行一次: " + dateFormat.format(new Date())); } @Scheduled(cron = "0 28 11 ? * *") public void fixTimeExecution() { System.out.println("在指定时间 " + dateFormat.format(new Date()) + "执行"); }}
配置类
MyConfig.java
package com.stormma.config;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.scheduling.annotation.EnableScheduling;/** * <p>Created by StormMa on 2017/1/28.</p> * * @author StormMa */@Configuration@EnableScheduling@ComponentScan("com.stormma")public class MyConfig {}
运行类
Client.java
package com.stormma.client;import com.stormma.config.MyConfig;import org.springframework.context.annotation.AnnotationConfigApplicationContext;/** * <P>Created by StormMa on 2017/1/28.</P> * * @author StormMa */public class Client { public static void main(String [] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfig.class); }}
1 0
- Spring计划任务(定时任务)
- Spring 计划任务
- Spring计划任务注意
- Spring 计划任务
- Spring 计划任务 Schedule
- Spring+Quartz实现计划任务
- Spring中使用任务计划
- Spring中使用任务计划
- spring - Scheduling Tasks 计划任务
- 第十章 Spring计划任务
- Spring Boot 启用计划任务
- Spring快速开启计划任务
- Spring Boot 计划任务(定时任务)
- 【Spring】Spring高级话题-计划任务-@EnableScheduling
- 【Spring】Spring高级话题-计划任务-@EnableScheduling
- spring的任务计划spring-Task
- spring计划任务,springMvc计划任务,Spring@Scheduled,spring定时任务
- spring 计划任务执行规律备忘
- 百练1833:排列(stl:next_permutation)
- Python Numpy 数据保存方法
- 有哪些操作可以导致direct reads(direct path reads)
- 百练2950:摘花生(模拟)
- ZooKeeper简介与安装
- Spring 计划任务
- 2016总结与2017的展望
- c语言如何识别无BOM的UTF8文本
- C语言程序设计 翁恺 oj3
- POJ3624 - Charm Bracelet(01背包)
- IOS 地区选择器(swift版本) AreaPickerView_swift
- opencv学习之直方图均衡化
- 六:函数返回值是一个引用
- Javascript的基本数据类型