From: <th...@us...> - 2010-12-06 21:23:22
|
Revision: 1981 http://azsmrc.svn.sourceforge.net/azsmrc/?rev=1981&view=rev Author: the8472 Date: 2010-12-06 21:23:15 +0000 (Mon, 06 Dec 2010) Log Message: ----------- close connections when purging them Modified Paths: -------------- mldht/trunk/DHTIndexer.jar mldht/trunk/lbms/plugins/mldht/indexer/db/PooledConnectionProvider.java Modified: mldht/trunk/DHTIndexer.jar =================================================================== (Binary files differ) Modified: mldht/trunk/lbms/plugins/mldht/indexer/db/PooledConnectionProvider.java =================================================================== --- mldht/trunk/lbms/plugins/mldht/indexer/db/PooledConnectionProvider.java 2010-12-06 11:15:00 UTC (rev 1980) +++ mldht/trunk/lbms/plugins/mldht/indexer/db/PooledConnectionProvider.java 2010-12-06 21:23:15 UTC (rev 1981) @@ -11,6 +11,9 @@ import java.util.concurrent.TimeUnit; import lbms.plugins.mldht.indexer.DHTIndexer; +import lbms.plugins.mldht.kad.DHT; +import lbms.plugins.mldht.kad.DHTLogger; +import lbms.plugins.mldht.kad.DHT.LogLevel; import org.hibernate.HibernateException; import org.hibernate.connection.ConnectionProvider; @@ -37,19 +40,27 @@ } public void closeConnection(Connection toClose) throws SQLException { - connectionPool.add(toClose); + if(!toClose.isClosed()) + connectionPool.add(toClose); } private void cleanPool() { try { - Connection c = connectionPool.poll(); - if(c != null && !c.isClosed() && connectionPool.size() < DHTIndexer.indexerScheduler.getPoolSize() && c.isValid(2)) - connectionPool.add(c); + Connection c = null; + while((c = connectionPool.poll()) != null) + { + if(!c.isClosed() && connectionPool.size() < DHTIndexer.indexerScheduler.getPoolSize() && c.isValid(2)) + { + connectionPool.add(c); + break; + } + + c.close(); + } } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + DHT.log(e, LogLevel.Error); } } @@ -75,7 +86,7 @@ public Connection getConnection() throws SQLException { Connection c = connectionPool.poll(); - if(c == null) + if(c == null || c.isClosed()) { c = driver.connect(jdbcUrl, connectConfig); c.setAutoCommit(false); @@ -89,6 +100,4 @@ } - - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |