使用Spring的@Scheduled实现定时任务
来源:互联网 发布:php 字符串查找函数 编辑:程序博客网 时间:2024/05/16 08:32
很简单,直接贴代码。
1、spring-task.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- spring扫描注解的配置 -->
<context:component-scan base-package="com.cmcc.admin.biz.task" />
<!-- 任务扫描注解 -->
<task:executor id="executor" pool-size="5" />
<task:scheduler id="scheduler" pool-size="10" />
<task:annotation-driven executor="executor"
scheduler="scheduler" />
</beans>
2、Task类
@Component
public class Task {
/**
* 定时计算。每天凌晨 01:00 执行一次
*/
@Scheduled(cron="0 0 1 * * *")
public void testTask() {
System.out.println("现在是凌晨1点,开始跑定时任务啦。。。");
}
}
这个是我打印出来的日志,周一过来看的。
=====================over============================
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- 使用Spring的@Scheduled实现定时任务
- json(pickle)用法记录
- 常见错误:赋值和恒等混淆
- hdu 6053 TrickGCD(容斥,分段,莫比乌斯函数)
- odoo在Windows平台下部署无内容显示问题
- 用arm-linux-gdb调试ARM上的应用程序
- 使用Spring的@Scheduled实现定时任务
- yii2.0 最简单rbac实现方法
- PCIe学习笔记(30)--- PL
- 获取iPhone手机 UDID的方式--一网打尽(无论有无MAC电脑)
- Python之路-python(mysql介绍和安装、pymysql、ORM sqlachemy)
- opencv 各种输出格式
- 老司机教你在windows不用软件隐藏重要文件
- 4种方式实现鼠标放上图片变大效果
- eclipse Ctrl +左键查看源代码Source not found