java Spring定时任务详解
来源:互联网 发布:冠能狗粮网络代理 编辑:程序博客网 时间:2024/05/15 23:21
1.创建一个调用业务层的类并要继承QuartzJobBean
例:Object obj = SpringContextUtil.getBean("tOrderService"); //获取spring实例bean
public class ConfirmOrderStateJob extends QuartzJobBean {
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
Object obj = SpringContextUtil.getBean("tOrderService");
if (null != obj) {// 非空再进行业务处理
TOrderService tOrderService = (TOrderService) obj;
tOrderService.doConfirmOrderStateJob();
}
}
}
2.创建一个properties文件
例如:quartz.properties
在xml文件中会被引用到
内容:如下例子
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class =org.quartz.simpl.RAMJobStore
3.创建xml文件
例如:frame-quartz-context.xml
内容:如下例子
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!--**************************************单机配置,每台节点均运行********************************-->
<!-- 统计定时任务-->
<bean id="newAcess" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.yxd.pris.common.job.ConfirmOrderStateJob</value>
</property>
</bean>
<!-- 统计访问sesion,每2分钟运行一次-->
<bean id="cronnewNewAcess" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="newAcess" />
<property name="cronExpression" value="0 */2 * * * ?" />
</bean>
<bean name="quartzSchedulerAccess"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
<property name="configLocation" value="classpath:cfg/quartz_access.properties" />
<property name="triggers">
<list>
<ref bean="cronnewNewAcess" />
</list>
</property>
<property name="autoStartup" value="true"></property>
</bean>
</beans>
4.实现业务逻辑
- java Spring定时任务详解
- java,spring定时任务
- java spring 定时任务
- Java 定时任务 与 Spring定时任务
- 详解java定时任务
- 详解java定时任务
- 详解java定时任务
- 详解java定时任务
- 详解java定时任务
- java定时任务详解
- 详解java定时任务
- 详解java定时任务
- 详解 java 定时任务
- 详解java定时任务
- 详解java定时任务
- 详解java定时任务
- 详解java定时任务
- Java定时任务详解
- 神牛的养成计划---可持久化trie
- 自动化测试中对Alert, 多窗口,下拉框的处理
- dedecms基础2012
- 安装appium
- USACO-Section1.3 Combination Lock[其他]
- java Spring定时任务详解
- 属性操作
- LogSegment分析
- MVC,MVP 和 MVVM 的图示
- Activiti的后台自动生成数据库表介绍
- jQuery选择器
- Linux学习笔记之系统管理
- 【读书笔记】大规模Web开发技术(第十六章 part2)
- 分形【分治递归】