Quartz 學習

想學習下Quatz用數據庫方式是怎麼用的。

一般之前用的方式是在spring中直接配置。邊學編記錄了。springside

<bean id="expiredAutoDaemonTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail">
			<bean
				class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
				<property name="targetObject">
					<ref bean="expiredAutoDaemon" />
				</property>
				<property name="targetMethod">
					<value>executeAutoExpired</value>
				</property>
				<property name="concurrent">
					<value>false</value>
				</property>
			</bean>
		</property>
		<property name="cronExpression">
			<value>0 0 2 * * ?</value>
		</property>
	</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

		<property name="triggers">
			<list>
			    <ref bean="expiredAutoDaemonTrigger"/>
			</list>
		</property>
	</bean>

配置好就可以了。直接調用service中的方法,一般用org.springframework.scheduling.quartz.CronTriggerBean

數據庫方式:下載svn代碼地址

http://svn.terracotta.org/svn/quartz/
現在下載版本也是用的1.6.6的。裏面有
當成是一個普通的web項目自己部署好就可以了。
創建數據的腳本在docs\dbTables下面。選擇自己用的數據庫。修改quartz.properties,我用的是mysql
#============================================================================
# Configure Main Scheduler Properties  
#============================================================================
 
org.quartz.scheduler.instanceName = TestScheduler
org.quartz.scheduler.instanceId = AUTO
 
#============================================================================
# Configure ThreadPool  
#============================================================================
 
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.threadPool.threadPriority = 4
 
#============================================================================
# Configure JobStore  
#============================================================================
 
org.quartz.jobStore.misfireThreshold = 60000
 
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
 
#org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
##org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.dataSource = myDS
#org.quartz.jobStore.tablePrefix = QRTZ_
#org.quartz.jobStore.isClustered = false
 
#============================================================================
# Configure Datasources  
#============================================================================
 
#org.quartz.dataSource.myDS.driver = oracle.jdbc.driver.OracleDriver
#org.quartz.dataSource.myDS.URL = jdbc:oracle:thin:@polarbear:1521:dev
#org.quartz.dataSource.myDS.user = quartz
#org.quartz.dataSource.myDS.password = quartz
#org.quartz.dataSource.myDS.maxConnections = 5
 
#org.quartz.dataSource.myDS.driver = org.postgresql.Driver
#org.quartz.dataSource.myDS.URL = jdbc:postgresql:dev
#org.quartz.dataSource.myDS.user = jhouse
#org.quartz.dataSource.myDS.password = 
#org.quartz.dataSource.myDS.maxConnections = 5
 
#============================================================================
# Configure Plugins 
#============================================================================
 
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin

org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
# init plugin will load jobs.xml as a classpath resource i.e. /jobs.xml if not found on file system
org.quartz.plugin.jobInitializer.fileNames=jobs.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = false
org.quartz.plugin.jobInitializer.failOnFileNotFound = false
org.quartz.plugin.jobInitializer.scanInterval = 30 
# org.quartz.plugin.jobInitializer.wrapInUserTransaction = true

org.quartz.plugin.jobInitializerMultiple.class = org.quartz.plugins.xml.JobInitializationPlugin
# init plugin will load jobs.xml as a classpath resource i.e. /jobs.xml and jobs2.xml if not found on file system
org.quartz.plugin.jobInitializerMultiple.fileNames=jobs2.xml,jobs3.xml
org.quartz.plugin.jobInitializerMultiple.overWriteExistingJobs = false
org.quartz.plugin.jobInitializerMultiple.failOnFileNotFound = false
# org.quartz.plugin.jobInitializerMultiple.wrapInUserTransaction = true
 
登錄後的用戶名和密碼在applicationContext.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:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">


	<bean id="authenticator"
		class="org.quartz.ui.web.security.SimpleAuthenticator">
		<property name="username">
			<value>quartz</value>
		</property>
		<property name="password">
			<value>quartz</value>
		</property>
	</bean>


	<bean id="logonAction"
		class="org.quartz.ui.web.action.LogonAction" scope="prototype">
		<property name="authenticator" ref="authenticator" />
	</bean>



<bean id="quartzUser" class="org.quartz.ui.web.security.User">
	<property name="username"><value>quartz</value></property>
	<property name="password"><value>quartz</value></property>
	<property name="roles">
	<map>
		<entry key="manager">
		<value>manager</value>
	</entry>
	</map>
</property>
</bean>

	<bean id="users" class="org.quartz.ui.web.security.Users">
	<property name="userMap">
	<map>
			<entry key="quartz">
				<ref bean="quartzUser"/>
			</entry>
	</map>
</property>
</bean>


</beans>







發佈了74 篇原創文章 · 獲贊 3 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章