Bug in Oracle Connection Pool (11.2.0.1.0)I used:
Documentation of UCP clearly says for 'maxConnectionReuseTime': borrowed connections are closed only after they are returned to the pool and the reuse time has been exceeded The Junit-Testcase on the other hand shows, that the connection is closed, while it is borrowed from pool and therefore raises an exception. So, should you continue to use Oracle Connection Pool nonetheless? If you do not need 'maxConnectionReuseTime', then yes. Otherwise no. I switched to 'maxConnectionReuseCount' as a work around (bleah). See also my thread. Unfortunately i am unable to file any request, so i am on lost position here.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.TestCase;
import oracle.ucp.UniversalConnectionPoolAdapter;
import oracle.ucp.admin.UniversalConnectionPoolManager;
import oracle.ucp.admin.UniversalConnectionPoolManagerImpl;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
public class UCPTest extends TestCase {
private String user = "xxx";
private String pass = "xxx";
private String url = "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = db.oracle.com)))";
private String poolname = "testpool";
private PoolDataSource pds;
private UniversalConnectionPoolManager mgr;
private int maxConnectionReUseTime = 5; // in seconds
@Override
protected void setUp() throws Exception {
Logger.getLogger("oracle.ucp").setLevel(java.util.logging.Level.FINEST);
Logger.getLogger("oracle.ucp.jdbc.PoolDataSource").setLevel(java.util.logging.Level.FINEST);
mgr = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();
mgr.setLogLevel(Level.FINE);
pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setUser(user);
pds.setPassword(pass);
pds.setURL(url);
pds.setInitialPoolSize(1);
pds.setMaxPoolSize(10);
pds.setConnectionPoolName(poolname);
// timer starts, when phys connection is created.
// borrowed connection is closed only after it is returned to the pool and reuse time has been exceeded (not while using it!)
pds.setMaxConnectionReuseTime(maxConnectionReUseTime);
mgr.createConnectionPool((UniversalConnectionPoolAdapter)pds);
mgr.startConnectionPool(poolname);
}
@Override
protected void tearDown() throws Exception {
mgr.destroyConnectionPool(poolname);
super.tearDown();
}
public void testPool() throws Exception {
// documentation: http://download.oracle.com/docs/cd/E14072_01/java.112/e12265.pdf
// assert that harvesting feature is OFF (equal to Integer.MAX_VALUE according to documentation
assertEquals(pds.getConnectionHarvestTriggerCount(), Integer.MAX_VALUE);
// assert that ttl is OFF and does not interfere
assertEquals(pds.getTimeToLiveConnectionTimeout(),0);
// documentation in page 4-3 says: "Borrowed connections are closed only after they are returned to the pool and the reuse time has been exceeded".
// => a borrowed connection is not closed!
// => a borrowed connection is closed only, when connection is returned to pool and reuse time has been exceeded
// so, borrow the connection from the pool and dont return it before reuse time
Connection c = pds.getConnection();
// do something with it for at least the maxconnectionreusetime
// this should not raise an exception, since we never return the borrowed connection before that reuse time
int workingTime = maxConnectionReUseTime + pds.getTimeoutCheckInterval()+5;
System.out.println(new Date());
try {
for(int i = 1; i < workingTime; i++) {
PreparedStatement ps = c.prepareStatement("select 1 from dual");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
// sunshine.
}
rs.close();
ps.close();
// sleep a second
Thread.sleep(1000);
}
} catch (SQLException ex) {
System.out.println(ex.getErrorCode()); // 31 means connection is closed
fail();
} finally {
System.out.println(new Date());
c.close();
}
}
}
Mon Mar 7 12:29:57 CET 2011
Feedback: public@ecopatz.de
|