|
I have applications with Tomcat and i implement ConnectionPoolListener in java beans. package pe.com.enterprise.util; import java.sql.*; import javax.sql.*; import javax.naming.*; import com.ibm.as400.access.*; public final class ConnectionPoolImpl implements ConnectionPoolListener { private AS400JDBCConnectionPool pool = null; public ConnectionPoolImpl( String driverName, String systemIP, String userName, String password, int initialConnections, int maxConnections ) throws SQLException { try { //load DB Driver Class.forName( driverName ); AS400JDBCConnectionPoolDataSource datasource = new AS400JDBCConnectionPoolDataSource( systemIP, userName, password ); datasource.setErrors( "full" ); datasource.setExtendedDynamic( true ); datasource.setCursorHold(false); //datasource.setTrueAutoCommit(true); datasource.setTransactionIsolation("none"); datasource.setPackage("APP"); datasource.setPackageCache(true); datasource.setPackageCriteria("select"); // Create an AS400JDBCConnectionPool object. this.pool = new AS400JDBCConnectionPool( datasource ); this.pool.addConnectionPoolListener( this ); this.pool.setMaxConnections( maxConnections ); if( initialConnections > 0 ) this.pool.fill( initialConnections ); } catch( ClassNotFoundException cnfe ) { throw new SQLException( "DataBase Driver (" + driverName + ") not found on classpath." ); } catch( ConnectionPoolException cpe ) { throw new SQLException( cpe.getMessage() ); } } public void close() { this.pool.close(); this.pool = null; } public synchronized Connection getConnection()throws SQLException { try { if (pool.getActiveConnectionCount() < pool.getMaxConnections() ){ return pool.getConnection(); } else{ System.out.println("Se paso el nro de conexiones"); while( pool.getActiveConnectionCount() >= pool.getMaxConnections() ) { /*try { Thread.sleep(20); } catch( InterruptedException ie ){}*/ } return pool.getConnection(); } } catch( ConnectionPoolException cpe ) { throw new SQLException( cpe.getMessage() ); } } //connection pool listener methods... public void connectionCreated(ConnectionPoolEvent event) { } public void connectionExpired(ConnectionPoolEvent event) { } public void connectionPoolClosed(ConnectionPoolEvent event) { } public void connectionReleased(ConnectionPoolEvent event) { } public void connectionReturned(ConnectionPoolEvent event) { } public void maintenanceThreadRun(ConnectionPoolEvent event) { } } I have a problem when use getConnection() and pool.getActiveConnectionCount() < pool.getMaxConnections(). I wait for free Connection but this never succeded. Then Tomcat return java.lang.OutMemoryError. I close all Connection, PreparedStatement and ResultSet. What's the problem??? Have some idea????
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.