我的漫漫程序之旅

专注于JavaWeb开发
随笔 - 39, 文章 - 310, 评论 - 411, 引用 - 0
数据加载中……

Quartz高级部分(Spring默认对Quartz的支持)

在Spring中使用Quartz也是很简单,Spring默认你Quartz提供了支持.
你甚至不需要添加任何额外的jar包.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
    
<bean name="quartzScheduler"
        class
="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        
<property name="triggers">
            
<list>
                
<ref bean="cronTrigger" />
            
</list>
        
</property>
        
<!-- 指定你属性文件的位置(非必须) -->
        
<property name="configLocation"
            value
="classpath:org/quartz/quartz.properties" />
    
</bean>

    
<bean id="cronTrigger"
        class
="org.springframework.scheduling.quartz.CronTriggerBean">
        
<property name="jobDetail" ref="jobDetail" />
        
<!--朝九晚五工作时间内每半小时执行一次-->
        
<property name="cronExpression" value="0 0/30 9-17 *,* * ?" />
    
</bean>

    
<!-- 使用pojo做job,指定pojo和method -->
    
<bean id="jobDetail"
        class
="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        
<!-- 这时关联你的计划类 -->
        
<property name="targetObject" ref="bookStockChecker" />
        
<!-- 你的计划类的具体方法 -->
        
<property name="targetMethod" value="check" />
    
</bean>

    
<!-- 图书库存检查类 -->
    
<bean id="bookStockChecker" class="org.quartz.BookStockChecker"
        autowire
="byName" lazy-init="true">
        
<!-- 这里为类的属性初始值 -->
        
<property name="minStock" value="100" />
    
</bean>
</beans>

资源文件:
#============================================================================
# 配置 Main Scheduler Properties
#
============================================================================
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 
= 10
org.quartz.threadPool.threadPriority 
= 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread 
= true

#
============================================================================
# 配置 JobStore
#
============================================================================
org.quartz.jobStore.misfireThreshold 
= 60000

#内存中JobStore
, 服务器重启时执行记录会丢失
org.quartz.jobStore.class 
= org.quartz.simpl.RAMJobStore

#数据库中JobStore
#org.quartz.jobStore.class 
= org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass
=org.quartz.impl.jdbcjobstore.MSSQLDelegate
#org.quartz.jobStore.driverDelegateClass
=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate


posted on 2008-05-09 11:13 々上善若水々 阅读(3106) 评论(0)  编辑  收藏 所属分类: opensource


只有注册用户登录后才能发表评论。


网站导航: