Hi everyone,
Is it a normal behaviour that C3P0 closes the connection shortly after creating it when Java's threading API is used?
I have a class that implements Runnable and is ran by the ExecutorService class. Hibernate initialises as usual and C3P0 creates the default 3 connections as shown in my log when the application starts up. However, shortly after, C3P0 starts shutting down the connections as shown below
Code:
2007-08-22 10:56:01,296 DEBUG [main] com.mchange.v2.c3p0.management.ActiveManagementCoordinator - MBean: com.mchange.v2.c3p0:type=PooledDataSource[1hgea9s7o12pek701n30f9|1da669c] unregistered.
2007-08-22 10:56:01,296 DEBUG [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] com.mchange.v2.async.ThreadPoolAsynchronousRunner - Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main] interrupted. Shutting down.
2007-08-22 10:56:01,296 DEBUG [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] com.mchange.v2.async.ThreadPoolAsynchronousRunner - Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main] interrupted. Shutting down.
2007-08-22 10:56:01,296 DEBUG [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] com.mchange.v2.async.ThreadPoolAsynchronousRunner - Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main] interrupted. Shutting down.
2007-08-22 10:56:01,296 DEBUG [main] com.mchange.v2.c3p0.management.ActiveManagementCoordinator - C3P0Registry mbean unregistered.
2007-08-22 10:56:01,296 DEBUG [Resource Destroyer in BasicResourcePool.close()] com.mchange.v2.resourcepool.BasicResourcePool - Preparing to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@d66426
2007-08-22 10:56:01,296 DEBUG [Resource Destroyer in BasicResourcePool.close()] com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool - Preparing to destroy PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@d66426
2007-08-22 10:56:01,296 DEBUG [Resource Destroyer in BasicResourcePool.close()] com.mchange.v2.c3p0.impl.NewPooledConnection - com.mchange.v2.c3p0.impl.NewPooledConnection@d66426 closed by a client.
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:491)
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:989)
at com.mchange.v2.resourcepool.BasicResourcePool.access$100(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$5.run(BasicResourcePool.java:1174)
2007-08-22 10:56:01,296 DEBUG [main] com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - com.mchange.v2.c3p0.PoolBackedDataSource@1da669c has been closed.
java.lang.Exception: DEBUG STACK TRACE for PoolBackedDataSource.close().
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.close(AbstractPoolBackedDataSource.java:417)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.close(AbstractPoolBackedDataSource.java:429)
at com.mchange.v2.c3p0.DataSources.destroy(DataSources.java:359)
at com.mchange.v2.c3p0.DataSources.destroy(DataSources.java:335)
at org.hibernate.connection.C3P0ConnectionProvider.close(C3P0ConnectionProvider.java:182)
at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:803)
at com.wings.controller.JustAMain.main(JustAMain.java:46)
2007-08-22 10:56:01,296 DEBUG [Resource Destroyer in BasicResourcePool.close()] com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool - Successfully destroyed PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@d66426
2007-08-22 10:56:01,296 DEBUG [Resource Destroyer in BasicResourcePool.close()] com.mchange.v2.resourcepool.BasicResourcePool - Successfully destroyed resource: com.mchange.v2.c3p0.impl.NewPooledConnection@d66426
2007-08-22 10:56:01,296 DEBUG [Resource Destroyer in BasicResourcePool.close()] com.mchange.v2.resourcepool.BasicResourcePool - Preparing to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@186f247
It happens even before i can even do a transaction.beginTransaction(). Does anyone know why this is happening? This wouldn't happen if i did not use threads.
I am using Java SE 5 update 12, Hibernate 3.2.4 sp1, default C3P0 package and Oracle 10g Express Edition.
Any insight is greatly appreciated. Thanks!