kxyz
kxyz

Reputation: 842

Quartz scheduler - each time new jdbc connection

I have problem with Quartz Scheduler and configuration for database. Every time scheduler check if new job exist is created new JDBC connections. How to avoid create new connection ?

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

And configuration

<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>

and datasource, the same for hibernate and quartz scheduler

<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>

Upvotes: 1

Views: 3354

Answers (1)

Nechaev Sergey
Nechaev Sergey

Reputation: 136

As far as I see you use org.springframework.jdbc.datasource.DriverManagerDataSource class as data source. According to the javadoc it creates jdbc connection every time someone call getConnection. I'm sure Quartz call this method internally.

To solve problem you should use pooled DataSource. For example, c3p0 (Look at com.mchange.v2.c3p0.ComboPooledDataSource)

Upvotes: 4

Related Questions