spring定时器
来源:互联网 发布:淘宝技术删除中差评 编辑:程序博客网 时间:2024/06/06 05:28
在spring框架中,如果要用的定时器功能,spring自己提供了定时器
使用spring的定时器,首先要到spring的配置文件中进行配置:
如:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/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">
<!--开启执行定时器功能-->
<task:annotation-driven />
<bean id="taskTest" class="org.test.TaskTest"></bean>
<task:scheduled-tasks>
<!-- 这里表示的是从第五秒开始 ,每三秒执行一次 -->
<task:scheduled ref="taskTest" method="say" cron="5/3 * * * * ?" />
<task:scheduled ref="taskTest" method="hello" cron="5/3 * * * * ?" />
</task:scheduled-tasks>
</beans>
注意:在头要加入: xmlns:task="http://www.springframework.org/schema/task"和http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
org.test.TaskTest类为自己定义的要执行的方法,如;
package org.test;
import java.util.Date;
public class TaskTest {
public void say() {
System.out.println("当前执行时间!!!" + new Date());
}
public void hello(){
System.out.println("hello ,又执行一次!!!");
}
}
- spring定时器
- Spring定时器
- Spring 定时器
- Spring定时器
- spring定时器
- Spring定时器
- spring 定时器
- Spring定时器
- spring定时器
- Spring定时器
- spring 定时器
- spring 定时器
- spring 定时器
- Spring定时器
- spring定时器
- spring 定时器
- spring 定时器
- spring定时器
- 资源限制阈值
- 农业银行K宝不能下载证书
- Ural 1081 Binary Lexicographic Sequence(DP)
- 梯度下降(Gradient Descent),一句代码,一个式子
- 第9周 项目2-3 运用for语句做循环程序求正负分数累加和
- spring定时器
- Cookie与Session机制,什么时候用Cookie,什么时候用Session
- Unity3D KeyCode
- CSS3如何实现超出指定文本以省略号显示效果
- 在 Unity 工程 (Project) 中使用 DLL(动态库)
- 金色十月线上编程比赛第二题:解密
- NGUI系列教程五(角色信息跟随)
- hdu 4442 Physical Examination(贪心)
- 对于同学提问问题答案的收集