[c3p0-users] Connection not returned to the pool
Status: Beta
Brought to you by:
swaldman
From: alex p. <ale...@y-...> - 2007-10-17 12:10:28
|
Hi. I must be doing something wrong but I can't seem to be able to return the connections to the pool after having used them. I'm using: c3p0-0.9.1.2 on stand-alnone mode. * Following the docs I start my pool as:* public static DataSource ds_pooled = null; try { ds_unpooled = DataSources.unpooledDataSource(cString); ds_pooled = DataSources.pooledDataSource( ds_unpooled, overrides); Connection conn = ds_pooled.getConnection(); // Setup the first connection to save us time later conn.close(); System.out.println("INFO: setupConnectionPool. Connection set"); } catch (SQLException ex) { System.out.println("EXCEPTION: setupConnectionPool. " + ex); terminate(); } *Then I use it as:* String sql = "whatever query"; Connection conn = ds_pooled.getConnection(); PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, some_value); ResultSet rs = ps.executeQuery(); if (rs.next()){ // do stuff with the results here } // And then close it: rs.close(); rs = null; ps.close(); ps = null; conn.close(); conn = null; None of the previous seems to close the pool, ie the resources stay active until the pool size is full and then the app hangs. I solved it by supplying to the overrides config options unreturnedConnection data: overrides.put("unreturnedConnectionTimeout", "300"); overrides.put("debugUnreturnedConnectionStackTraces", "true"); Then I have the error log full of: java.lang.Exception: DEBUG ONLY: Overdue resource check-out stack trace. at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource( BasicResourcePool.java:506) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection( C3P0PooledConnectionPool.java:525) at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection( AbstractPoolBackedDataSource.java:128) ... Any thoughts will be greatly appreciated. Alex |