2015-06-19 34 views
0

我有Quartz Scheduler和數據庫配置的問題。每當調度程序檢查新作業是否存在時,都會創建新的JDBC連接。如何避免創建新的連接?石英調度程序 - 每次新的jdbc連接

2015-06-19 10:42:05,522 DEBUG DriverManagerDataSource:142 - Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/db?characterEncoding=UTF-8] 
2015-06-19 10:42:05,544 DEBUG LocalDataSourceJobStore:3182 - Found 0 triggers that missed their scheduled fire-time. 
2015-06-19 10:42:05,545 DEBUG DataSourceUtils:327 - Returning JDBC Connection to DataSource 
2015-06-19 10:42:07,522 DEBUG LocalDataSourceJobStore:3933 - MisfireHandler: scanning for misfires... 
2015-06-19 10:42:07,522 DEBUG DriverManagerDataSource:142 - Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/db?characterEncoding=UTF-8] 
2015-06-19 10:42:07,539 DEBUG LocalDataSourceJobStore:3182 - Found 0 triggers that missed their scheduled fire-time. 
2015-06-19 10:42:07,539 DEBUG DataSourceUtils:327 - Returning JDBC Connection to DataSource 

而且配置

<bean id="scheduler" name="scheduler" 
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean" 
    scope="singleton"> 
    <property name="quartzProperties"> 
     <props> 

      <prop key="org.quartz.scheduler.instanceId">AUTO</prop> 
      <prop key="org.quartz.scheduler.instanceName">USER_JOBS</prop> 
      <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop> 
      <prop key="org.quartz.jobStore.driverDelegateClass"> 
       org.quartz.impl.jdbcjobstore.StdJDBCDelegate 
      </prop> 
      <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop> 
      <prop key="org.quartz.jobStore.isClustered">false</prop> 
      <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop> 
      <prop key="org.quartz.jobStore.misfireThreshold">2000</prop> 
     </props> 
    </property> 

    <property name="dataSource"> 
     <ref bean="dataSource" /> 
    </property> 
</bean> 

和數據源,同爲休眠和石英調度

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="${db.driver}" /> 
    <property name="url" value="${db.url}" /> 
    <property name="username" value="${db.username}" /> 
    <property name="password" value="${db.password}" /> 
</bean> 
+3

您應該使用池數據源http://stackoverflow.com/questions/9745165/what-pooled-data-source-should-i-use-for-spring-3- 1-0-hibernate-4-0-1-final-an – Jens

+0

@Jens我認爲這實際上是對這個問題的回答。在我的腦中增加了一些東西。謝謝.. –

回答

3

至於我看你用org.springframework.jdbc.datasource.DriverManagerDataSource類作爲數據源。根據javadoc,每次有人致電getConnection時,它會創建jdbc連接。我確定Quartz在內部調用這個方法。

要解決問題,您應該使用池數據源。例如,c3p0(請看com.mchange.v2.c3p0.ComboPooledDataSource

+0

我用org.apache.commons.dbcp.BasicDataSource和它的工作,無論如何:) – kxyz

+0

我認爲c3p0比Apache DBCP更多的生產準備。無論如何,請隨意選擇最舒適的圖書館) –

+0

我正在改變c3p0:)謝謝 – kxyz