求Spring 定时器的例子代码

tongshushan 2010-08-17 02:35:28
求Spring 定时器的例子代码
...全文
267 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanbin_0521 2010-11-26
  • 打赏
  • 举报
回复
471050915@qq.com 谢谢给我一份
liufeng0209 2010-08-19
  • 打赏
  • 举报
回复
quartz 直接使用service的方法实现定时器多好.
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">

<!-- 普通bean -->
<bean id="luceneService" class="cn.ait.cms.service.LuceneServiceImpl"/>
<bean id="publishServiceImpl" class="cn.ait.cms.service.PublishServiceImpl"/>

<!-- 作业 :不允许并发执行,避免堵塞 -->
<bean id="jobDetail_lucene" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="luceneService"/>
<property name="targetMethod" value="creatIndex"/>
<property name="concurrent" value="false" />
</bean>
<bean id="jobDetail_publish" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="publishServiceImpl"/>
<property name="targetMethod" value="publishMainCascade"/>
<property name="concurrent" value="false" />
</bean>
<!-- 触发器:循环触发
<bean name="testTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="jobDetail_event"/> -->
<!-- 定时任务,延迟启动,不占用spring初始化事件
<property name="startDelay" value="60000"/> -->
<!-- 定时任务间隔时间
<property name="repeatInterval" value="10000"/>-->
<!-- 定时任务执行次数,-1表示永久执行
<property name="repeatCount" value="-1"/>
<property name="jobDataAsMap">
<map>
<entry key="count" value="10"/>
</map>
</property>
</bean> -->
<!-- 触发器:某一时间进行触发 -->
<bean name="luceneTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref local="jobDetail_lucene"/>
</property>
<property name="cronExpression">
<value>0 23 15 * * ?</value><!-- 每天凌晨2时执行 -->
</property>
</bean>
<bean name="publishTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref local="jobDetail_publish"/>
</property>
<property name="cronExpression">
<value>0 0 4 * * ?</value><!-- 每天凌晨4时执行 -->
</property>
</bean>
<!-- 计划 -->
<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="luceneTrigger"/>
<ref bean="publishTrigger"/>
</list>
</property>
</bean>
</beans>
East271536394 2010-08-18
  • 打赏
  • 举报
回复

Spring 定时器:

http://blog.csdn.net/East271536394/archive/2010/06/21/5685066.aspx

http://blog.csdn.net/East271536394/archive/2010/06/21/5685066.aspx

package com.east.spring.quartz;

import java.util.Date;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.springframework.scheduling.quartz.QuartzJobBean;
/**
*
* @author East(张栋芳) QQ:271536394
* @date:2008-6-18
* @content:EmailReportJob
* @version 1.0
*/
public class EmailReportJob extends QuartzJobBean{

@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
// TODO
System.out.println("===============QuartzJobBean================EmailReportJob is running"+new Date());

}

}


hatsubun2 2010-08-18
  • 打赏
  • 举报
回复
给我也发一份
谢谢
122218946@qq.com
跟着Mic学架构 2010-08-17
  • 打赏
  • 举报
回复
把邮箱发给我。 我发给你。
猿敲月下码 2010-08-17
  • 打赏
  • 举报
回复
留下邮箱

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧