Search code examples
javaspringmavenquartz-schedulerc3p0

Adding quartz to project breaks jdbc dataSource


I've already found out what was the problem, but decided to post it here, in case anyone else is banging head against the same wall.

I've added the latest version of quartz scheduler to my project:

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

And suddenly tests started falling with:

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [ my sql ]; SQL state [null]; error code [0]; An SQLException was provoked by the following failure: java.lang.InterruptedException; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException  

Even more weird, when I've moved quartz dependency to another module, they started to fail with different exception:

Could not get JDBC Connection; nested exception is java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource[ identityToken -> z8kfsx9b1qeyobp10iytmq|796c39ad, dataSourceName -> z8kfsx9b1qeyobp10iytmq|796c39ad ] has been closed() -- you can no longer use it.

So, Spring closed my ComboPooledDataSource, but why?

Removing quartz or changing it's version to 1.8.x helps. Exceptions happen even without instantiating any quartz object.


Solution

  • Quartz uses c3p0 jdbc pool for it's distributed job storage since version 2.x, and my project uses c3p0 too, but the newer 0.9.5 version, while the quartz uses 0.9.1.1. These versions are fairly different, the old one from quartz came first in my classpath, causing runtime exceptions. Since I don't use quartz distributed job storage, I've solved the problem by excluding transitive c3p0 dependency:

        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
            <!-- old c3p0 (0.9.1.1) in class path causes destruction of ComboPooledDataSource-->
            <exclusions>
                <exclusion>
                    <groupId>c3p0</groupId>
                    <artifactId>c3p0</artifactId>
                </exclusion>
            </exclusions>
        </dependency>