使用spring的@Scheduled注解执行定时任务,启动项目不输出警告
在applicationContext.xml中添加:
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd"> <task:annotation-driven executor="myExecutor" scheduler="myScheduler" />
<task:executor id="myExecutor" pool-size="5" />
<task:scheduler id="myScheduler" pool-size="10" />
java代码:
@Component
public class CleanExpireTokenTask { private Logger logger = LoggerFactory.getLogger(LogTag.BUSINESS); @Scheduled(cron = "0 * * * * ?")
public void startUpdateSaleThread(){
try{
System.out.println("check token expire");
}catch(Exception e){
logger.error("Make salesReport faild",e);
}
}
}
注意:
实现类上要加注解@Component
定时器的任务方法不能有返回值
@Resource(name = "myScheduler")
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
/**
* 等待正在执行的定时任务执行完毕,不再执行新的定时任务,
*/
public void shutdown(){
threadPoolTaskScheduler.shutdown();
// 等待任务执行完毕
while(threadPoolTaskScheduler.getActiveCount() > 0){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
使用spring的@Scheduled注解执行定时任务,启动项目不输出警告的更多相关文章
- Spring 的@Scheduled注解实现定时任务运行和调度
Spring 的@Scheduled注解实现定时任务运行和调度 首先要配置我们的spring.xml --- 即spring的主配置文件(有的项目中叫做applicationContext.xm ...
- spring @Scheduled注解执行定时任务
以前框架使用quartz框架执行定时调度问题. 这配置太麻烦.每个调度都需要多加在spring的配置中. 能不能减少配置的量从而提高开发效率. 最近看了看spring的 scheduled的使用注解的 ...
- quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
配置quartz 在spring中需要三个jar包: quartz-1.6.5.jar.commons-collections-3.2.jar.commons-logging-1.1.jar 首先要配 ...
- 使用spring @Scheduled注解执行定时任务
以前框架使用quartz框架执行定时调度问题. 老大说这配置太麻烦.每个调度都需要多加在spring的配置中. 能不能减少配置的量从而提高开发效率. 最近看了看spring的 scheduled的使用 ...
- 【转】使用spring @Scheduled注解执行定时任务
http://blog.csdn.net/sd4000784/article/details/7745947 以前框架使用quartz框架执行定时调度问题. 老大说这配置太麻烦.每个调度都需要多加在s ...
- 使用轻量级Spring @Scheduled注解执行定时任务
WEB项目中需要加入一个定时执行任务,可以使用Quartz来实现,由于项目就一个定时任务,所以想简单点,不用去配置那些Quartz的配置文件,所以就采用了Spring @Scheduled注解来实现了 ...
- 使用spring @Scheduled注解执行定时任务、
http://blog.csdn.net/sd4000784/article/details/7745947,留下来备用.
- Spring Boot 使用 @Scheduled 注解创建定时任务
在项目开发中我们经常需要一些定时任务来处理一些特殊的任务,比如定时检查订单的状态.定时同步数据等等. 在 Spring Boot 中使用 @Scheduled 注解创建定时任务非常简单,只需要两步操作 ...
- 使用spring @Scheduled注解运行定时任务、
曾经框架使用quartz框架运行定时调度问题. 老大说这配置太麻烦.每一个调度都须要多加在spring的配置中. 能不能降低配置的量从而提高开发效率. 近期看了看spring的 scheduled的使 ...
随机推荐
- 如何将Sphinx生成的html文档集成进入Django
参考 http://stackoverflow.com/questions/10594618/django-and-sphinx-how-to-view-the-html-sphinx-generat ...
- Linux下多线程下载利器 axel
参考 https://teddysun.com/377.html 使用示例: axel -an https://ubuntu-mate.org/raspberry-pi/ubuntu-mate-16. ...
- mysql nonInstall 版本的安装与配置
最近用到mysql,发现如果想使用最新版本64 bit mysql 需要独特的配置和使用方式 结合最近的研究总结一下安装过程. 首先下载:http://dev.mysql.com/downloads/ ...
- c模拟c++ const 转换
#include <stdio.h> int main(){ const int constant = 21; const int* const_p = &constant; in ...
- 循环冗余码crc
待编码的有效信息组多项式:M(x) 生成多项式(产生校验码的多项式):G(x) 余数多项式:R(x) 商:Q(x) 生成多项式是四次的,所以某个多项式除以生成多项式的余式肯定是三次的,所以要加四位00 ...
- 自定义注解之运行时注解(RetentionPolicy.RUNTIME)
对注解概念不了解的可以先看这个:Java注解基础概念总结 前面有提到注解按生命周期来划分可分为3类: 1.RetentionPolicy.SOURCE:注解只保留在源文件,当Java文件编译成clas ...
- linux下用c实现ls命令
struct dirent中的几个成员: d_type:4表示为目录,8表示为文件 d_reclen:16表示子目录或文件,24表示非子目录 d_name:目录或文件的名称 #include < ...
- swift中 if let 与 guard let 对比,guard会降低一个分支
//用if let与guard let实现同一效果,会发现guard降低一个分支 //可以用if var guard var 表示定义的变量能修改值 func test(){ let name:Str ...
- SQL Server删除重复行的6个方法
SQL Server删除重复行是我们最常见的操作之一,下面就为您介绍六种适合不同情况的SQL Server删除重复行的方法,供您参考. 1.如果有ID字段,就是具有唯一性的字段 delect ta ...
- Linux 系统中堆栈的使用方法
本节内容概要描述了Linux内核从开机引导到系统正常运行过程中对堆栈的使用方式.这部分内容的说明与内核代码关系比较密切,可以先跳过.在开始阅读相应代码时再回来仔细研究. Linux 0.12系统中共使 ...