`
frank-liu
  • 浏览: 1664612 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring quartz学习总结: cluster的配置和示例

 
阅读更多

简介

    在前面一篇文章里我们讨论了quartz和spring quartz的基本流程以及配置,这里针对一些quartz应用的场景和配置重点解读一下quartz的cluster配置和应用。

 

cluster配置

    在前面的执行quartz任务的环境里,我们都是在单独的一台机器上执行任务。这种单点执行的方式存在着一些问题。比如说,如果需要执行的任务量比较大,单台机器处理不过来。另外,如果这单独的节点失效了,整个节点上执行的所有任务也就都失败了。至少从这两点来说,如果我们要解决些问题的话,就需要考虑去除单点失效的问题并使用负载均衡来提高性能。

    说了这么多,其实在quartz里采用cluster模式的配置就是来解决上述问题的。quartz的cluster配置模型和我们传统的一些cluster系统模型有点不一样。一般的系统我们可能会考虑用LVS, keepalived等之类的东西来配,而这里是采用一个集中的数据库来保证负载均衡。它的配置模型如下:

 

    这种模型是怎么保证系统的高可用性和性能的呢?在这里,因为每个节点都执行不同的job,我们必须保证对于给定的任务只是在单独的一个节点上执行。所以当cluster里最先能够抢占到该任务的节点执行的时候,它会对数据库里对应这个任务的行加锁,然后后续的就不能再去占用了。通过利用锁的机制,这里也比较容易实现一个负载均衡,每次节点只要去取到那些没有被加锁的任务执行就可以了。关于quartz的内部执行细节会在后续的文章里描述。

   很明显,如果要在一个集群的模式下设置多个节点,每个节点必然会执行一到多个任务。这些任务的分配和执行情况需要记录和跟踪。同时怎么来调度资源协调它们也是一个需要考虑的问题。好在quartz里面已经提供了一些默认的配置支持,比如线程池和数据库连接池。一个典型的示例配置如下:

 

 

#============================================================================     
# Configure Main Scheduler Properties       
#============================================================================     
org.quartz.scheduler.instanceName = MyClusteredScheduler     
org.quartz.scheduler.instanceId = AUTO     
#============================================================================     
# Configure ThreadPool       
#============================================================================     
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool     
org.quartz.threadPool.threadCount = 25     
org.quartz.threadPool.threadPriority = 5     
#============================================================================     
# Configure JobStore       
#============================================================================     
org.quartz.jobStore.misfireThreshold = 60000     
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX     
org.quartz.jobStore.driverDelegateClass =
org.quartz.impl.jdbcjobstore.oracle.OracleDelegate     
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = myDS     
org.quartz.jobStore.tablePrefix = QRTZ _   
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000     
#============================================================================     
# 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.validationQuery=select 0 from dual
   因为需要配置成集群的模式,这里所有的任务数据需要记录到数据库中间。而以往默认创建的scheduler都是将任务数据记录在ramstore里,也就是这些数据都保存在内存中。另外,既然在多个节点中执行任务,每个任务执行的时间长短已经启动的时间点都不一样。所以需要为它们安排一个线程池来方便调度。同时,多个节点的更新都要访问数据库,所以这里对数据库的连接也最好使用连接池。前面的示例中使用了oracle的thin连接,并将线程池的容量配置成25个。

 

  到这里,cluster的基本配置已经差不多了。我们来结合具体的示例看看配置运行的结果。

 

示例

quartz api示例

 

  我们可以开始第一个最简单的示例,在这个示例里先不使用任何spring相关的配置,而是用原生的quartz api。首先创建一个maven工程SimpleQuartzCluster, 其pom.xml文件如下:

 

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.chanjet.chanapp</groupId>
  <artifactId>SimpleQuartzCluster</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>SimpleQuartzCluster</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>4.11</junit.version>
	<quartz.version>2.1.6</quartz.version>
	<mysql.connector.version>5.1.10</mysql.connector.version>
  </properties>

  <dependencies>
    <dependency>
		<groupId>org.quartz-scheduler</groupId>
		<artifactId>quartz</artifactId>
		<version>${quartz.version}</version>
	</dependency>

	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>${mysql.connector.version}</version>
	</dependency>
		
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
   因为考虑到后面我们将cluster的数据保存到mysql数据库中,所以这里引入了mysql-connector,在实际的应用中可以引入需要的库。

 

  和原来的套路一样,我们先定义一个简单的job实现:

 

 

package com.chanjet.chanapp;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class SimpleJob implements Job {

	public void execute(JobExecutionContext context) throws JobExecutionException {
		System.out.println("Job executed...");
	}
}
   简单,不解释。

 

  然后我们将定义JobDetail, trigger的代码放到执行的main方法里:

 

package com.chanjet.chanapp;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;


public class App 
{
    public static void main( String[] args ) throws SchedulerException, InterruptedException
    {
    	SchedulerFactory sf = new StdSchedulerFactory();
    	Scheduler sched = sf.getScheduler();
    	
        JobDetail job = JobBuilder.newJob(SimpleJob.class).build();
        
        Trigger trigger = TriggerBuilder
        		.newTrigger()
        		.withIdentity("testTrigger1", "group1")
        		.withSchedule(CronScheduleBuilder.cronSchedule("0/4 * * * * ?"))
        		.build();
        
        sched.scheduleJob(job, trigger);
        sched.start();
        Thread.sleep(90L * 1000L);
        sched.shutdown(true);
    }
}
     我们定义了job,然后通过trigger每4秒钟启动一次job。这里的代码和前面的文章里讲到的示例一样,没有什么特殊的地方。

 

  稍微有点不一样的地方是我们在这里还要添加一个properties文件,我们放到resources的目录下面,properties文件名为quartz.properties:

 

#============================================================================
# Configure Main Scheduler Properties  
#============================================================================

org.quartz.scheduler.instanceName: TestScheduler1
org.quartz.scheduler.instanceId: instance1

org.quartz.scheduler.skipUpdateCheck: true

#============================================================================
# Configure ThreadPool  
#============================================================================

org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 5
org.quartz.threadPool.threadPriority: 5

#============================================================================
# Configure JobStore  
#============================================================================

org.quartz.jobStore.misfireThreshold: 60000

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.dataSource=myDS
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true

#============================================================================
# Other Example Delegates
#============================================================================
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v6Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v7Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DriverDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.MSSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PointbaseDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.WebLogicDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.WebLogicOracleDelegate

#============================================================================
# Configure Datasources  
#============================================================================

org.quartz.dataSource.myDS.driver: com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL: jdbc:mysql://localhost:3306/qrtz
org.quartz.dataSource.myDS.user: root
org.quartz.dataSource.myDS.password: pwd
org.quartz.dataSource.myDS.maxConnections: 5
org.quartz.dataSource.myDS.validationQuery: select 0

#============================================================================
# Configure Plugins 
#============================================================================

#org.quartz.plugin.shutdownHook.class: org.quartz.plugins.management.ShutdownHookPlugin
#org.quartz.plugin.shutdownHook.cleanShutdown: true


#org.quartz.plugin.triggHistory.class: org.quartz.plugins.history.LoggingJobHistoryPlugin
   这里的resources是我们创建的一个source folder,在执行的时候这个目录里的内容可以被jvm来装载。因为它是被定义在classpath中的。

 

  如果我们简单的执行程序,会看到如下的输出:

 

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Dec 17, 2014 6:31:10 AM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Dec 17, 2014 6:31:10 AM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]
Dec 17, 2014 6:31:10 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kfsx96ollhm9r8reo7|719f9c2e, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kfsx96ollhm9r8reo7|719f9c2e, idleConnectionTestPeriod -> 50, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/qrtz, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 120, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> select 0, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> true, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
Job executed...
Job executed...
Job executed...
    这里的输出内容每4秒钟打印一次。按照前面的配置内容,我们去看数据库里的内容:

 

 

mysql> select * from QRTZ_CRON_TRIGGERS;
+----------------+--------------+---------------+-----------------+---------------------+
| SCHED_NAME     | TRIGGER_NAME | TRIGGER_GROUP | CRON_EXPRESSION | TIME_ZONE_ID        |
+----------------+--------------+---------------+-----------------+---------------------+
| TestScheduler1 | testTrigger1 | group1        | 0/4 * * * * ?   | America/Los_Angeles |
+----------------+--------------+---------------+-----------------+---------------------+
1 row in set (0.00 sec)
   因为前面代码里定义了触发器trigger是crontrigger,这里就显示了trigger name和group。

 

 

mysql> select * from QRTZ_SCHEDULER_STATE;
+----------------+---------------+-------------------+------------------+
| SCHED_NAME     | INSTANCE_NAME | LAST_CHECKIN_TIME | CHECKIN_INTERVAL |
+----------------+---------------+-------------------+------------------+
| TestScheduler1 | instance1     |     1418826761247 |             7500 |
+----------------+---------------+-------------------+------------------+
1 row in set (0.00 sec)
  配置文件里定义的内容instancename, instanceid在这里都有对应上了。

 

  为什么我们定义好之后只要把properties文件放到classpath就可以实现这个cluster的效果呢?其实原因很简单,quartz已经帮我们做了大部分的事情了。在默认的情况下quartz会去找classpath中默认名字为quartz.properties的文件,然后按照这里的配置来执行。如果我们的classpath里没有这个文件的话,它会去装载quartz jar包里的quartz.properties文件。在这个文件里,相当于它的默认配置,是没有使用持久化的存储,而是使用的ramstore。在实际应用的过程中,为了防止一个job被重复启动和并发的执行,有时候我们需要在job的定义实现上添加一些限制,如@PersistJobDataAfterExecution @DisallowConcurrentExecution。

  这样,一个最简单的quartz cluster示例就完成了。我们再来看看结合spring的情况下该怎么配。

 

spring quartz示例

    我们首先建一个maven工程SpringQuartzClusterSample,其pom.xml文件配置如下:

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.yunzero</groupId>
  <artifactId>SpringQuartzClusterSample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>SpringQuartzClusterSample</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>4.0.4.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>4.0.4.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz</artifactId>
			<version>2.2.1</version>
		</dependency>

		<!-- jdbc driver begin -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.21</version>
			<scope>runtime</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>4.0.4.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
  </dependencies>
</project>

     这里主要引用了spring的一些基本配置和运行时需要访问数据库的jdbc driver。

    然后我们定义一个实现的job:

 

package com.yunzero;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.scheduling.quartz.QuartzJobBean;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class SimpleJob extends QuartzJobBean {

	@Override
	protected void executeInternal(JobExecutionContext arg0)
			throws JobExecutionException {
		System.out.println("Job started..");
	}

}

     也是一个简单的打印输出。

    剩下的就是在配置文件里配置好jobdetails, triggers等这些:

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="firstJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
		<property name="jobClass" value="com.yunzero.SimpleJob"/>
		<property name="durability" value="true" />	
		<property name="requestsRecovery" value="true" />
	</bean>
	
	<bean id="firstTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail" ref="firstJobDetail" />
		<property name="cronExpression" value="0/5 * * ? * * *" />
	</bean>
	
	<bean name="quartzScheduler"
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="configLocation" value="classpath:quartz.properties" />
		<property name="jobDetails">
			<list>
				<ref bean="firstJobDetail"/>
			</list>
		</property>
		<property name="triggers">
			<list>
				<ref bean="firstTrigger"/>
			</list>
		</property>
	</bean>	

</beans>

   我们这里和普通的配置差不多,这里唯一有差异的两个地方是在jobDetails里面设置它的durability属性为true,另外还在quartzScheduler里配置了configLocation,它引用了quartz.properties文件。在quartz.properties里我们配置了计划任务集群的详细信息:

 

#============================================================================
# Configure Main Scheduler Properties  
#============================================================================

org.quartz.scheduler.instanceName: TestScheduler1
org.quartz.scheduler.instanceId: instance1

org.quartz.scheduler.skipUpdateCheck: true

#============================================================================
# Configure ThreadPool  
#============================================================================

org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 5
org.quartz.threadPool.threadPriority: 5

#============================================================================
# Configure JobStore  
#============================================================================

org.quartz.jobStore.misfireThreshold: 60000

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.dataSource=myDS
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true

#============================================================================
# Other Example Delegates
#============================================================================
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v6Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v7Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DriverDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.MSSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PointbaseDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.WebLogicDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.WebLogicOracleDelegate

#============================================================================
# Configure Datasources  
#============================================================================

org.quartz.dataSource.myDS.driver: com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL: jdbc:mysql://localhost:3306/qrtz
org.quartz.dataSource.myDS.user: root
org.quartz.dataSource.myDS.password: test
org.quartz.dataSource.myDS.maxConnections: 5
org.quartz.dataSource.myDS.validationQuery: select 0

#============================================================================
# Configure Plugins 
#============================================================================

#org.quartz.plugin.shutdownHook.class: org.quartz.plugins.management.ShutdownHookPlugin
#org.quartz.plugin.shutdownHook.cleanShutdown: true


#org.quartz.plugin.triggHistory.class: org.quartz.plugins.history.LoggingJobHistoryPlugin

    这部分和前面的配置基本上没有差异。然后剩下的就是启动spring container的部分:

 

package com.yunzero;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class App 
{
    public static void main( String[] args )
    {
    	ApplicationContext springContext = 
    			new ClassPathXmlApplicationContext("applicationContext.xml");
    }
}

     如果我们运行程序的话,会得到如下的输出:

 

Dec 22, 2014 10:41:04 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3344c133: startup date [Mon Dec 22 22:41:04 CST 2014]; root of context hierarchy
Dec 22, 2014 10:41:04 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Dec 22, 2014 10:41:04 PM org.springframework.scheduling.quartz.SchedulerFactoryBean initSchedulerFactory
INFO: Loading Quartz config from [class path resource [quartz.properties]]
Dec 22, 2014 10:41:04 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Dec 22, 2014 10:41:04 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]
Dec 22, 2014 10:41:04 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kfsx96vr5hgx1nwo0d3|109999f1, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kfsx96vr5hgx1nwo0d3|109999f1, idleConnectionTestPeriod -> 50, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/qrtz, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 120, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> select 0, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> true, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
Dec 22, 2014 10:41:05 PM org.springframework.context.support.DefaultLifecycleProcessor start
INFO: Starting beans in phase 2147483647
Dec 22, 2014 10:41:05 PM org.springframework.scheduling.quartz.SchedulerFactoryBean startScheduler
INFO: Starting Quartz Scheduler now
Job started..
Job started..
Job started..
Job started..
Job started..
Job started..

   因为配置的任务是每5秒钟执行一次,所以每次会在屏幕打印输出内容。如果我们去检查数据库的话,也会发现和上面示例类似的内容。

    这样,一个spring quartz的cluster示例就配置完成了。具体的细节可以参照后面的附件。

 

参考材料

http://quartz-scheduler.org/generated/2.2.1/html/qs-all/#page/Quartz_Scheduler_Documentation_Set%2Fre-cls_cluster_configuration.html%23

http://pawel-malczyk.pl/wordpress/?p=240

http://tech.meituan.com/mt-crm-quartz.html

  • 大小: 23.5 KB
分享到:
评论
3 楼 MYLOVE1000 2017-06-12  
里面的表quartz不会自动创建
2 楼 frank-liu 2015-02-04  
在世界的中心呼喚愛 写道
这个数据库是quartz它自己创建的吧

数据库还是需要自己手动的创建,然后再.properties文件里datasource部分给配置上,里面的表quartz会自动创建。
1 楼 在世界的中心呼喚愛 2015-02-03  
这个数据库是quartz它自己创建的吧

相关推荐

Global site tag (gtag.js) - Google Analytics