Saturday, November 27, 2010

Connection pool overload on Weblogic server - forcibly release inactive connection

The number of inactive seconds on a reserved connection before WebLogic Server reclaims the connection and releases it back into the connection pool.

You can use the Inactive Connection Timeout feature to reclaim leaked connections - connections that were not explicitly closed by the application. Note that this feature is not intended to be used in place of properly closing connections.

When set to 0, the feature is disabled.

MBean Attribute (Does not apply to application modules) :
JDBCConnectionPoolParamsBean.InactiveConnectionTimeoutSeconds



Test classes which overload connection pool by holding connections
package dave;

import java.sql.Connection;
import java.sql.SQLException;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
* Session Bean implementation class TestSesssionEJB
*/
@Stateless(mappedName = "TestSesssionEJB")

public class TestSesssionEJB implements TestSesssionEJBRemote, TestSesssionEJBLocal {

/**
* Default constructor.
*/
public TestSesssionEJB() {


}

//@Resource (name="jdbc/XE")
//javax.sql.DataSource ds;

public String hello(String name){

System.out.println("Hello" + name);

InitialContext ic;
DataSource dsLookup = null;
try {
ic = new InitialContext();

dsLookup = (DataSource) ic
.lookup("jdbc/XE");
} catch (NamingException e) {
e.printStackTrace();
}


for(int i=0; i<15;i++){
Connection conn = null;
try {
conn = dsLookup.getConnection();
DbExecutor de = new DbExecutor(conn);
new Thread(de).start();
} catch (SQLException e) {
e.printStackTrace();
}

}

System.out.println("Main: started all");

return name;

}



}



package dave;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DbExecutor implements Runnable {

Connection conn;

public DbExecutor(Connection conn) {
this.conn = conn;
}

@Override
public void run() {
try {
Thread thread = Thread.currentThread();

System.out.println("Start thread.id=" + thread.getId());

PreparedStatement stmt = conn
.prepareStatement("select * from dave");



System.out.println("Thread id=" + thread.getId() +
" Query dave db using container injected ds thread.id=");

stmt.execute();

ResultSet rs = stmt.getResultSet();

try {
System.out.println("Thread id=" + thread.getId() +
" gor result, going to sleep for 60 s");
Thread.sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
}

while (rs.next()) {
System.out.println("Thread id=" +"dave=" + rs.getString("DSTR") + " id="
+ rs.getInt("ID"));
}

} catch (SQLException e) {
e.printStackTrace();
}

}





}


Overloaded JDBC connection pool statistics in Admin console



Admin server log for connection forcibly taken back by Weblogic
<Nov 27, 2010 12:22:25 PM CET> <Warning> <Common> <BEA-000620> <Forcibly releasing inactive resource "autoCommit=true,enabled=true,isXA=true,isJTS=false,vendorID=0,connUsed=false,doInit=false,'null',destroyed=false,poolname=XE,appname=null,moduleName=null,connectTime=100,dirtyIsolationLevel=false,initialIsolationLevel=2,infected=false,lastSuccessfulConnectionUse=1290856766085,secondsToTrustAnIdlePoolConnection=10,currentUser=java.lang.Exception
at weblogic.jdbc.common.internal.ConnectionEnv.setup(ConnectionEnv.java:318)
at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:344)
at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:322)
at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:438)
at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:317)
at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:93)
at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:61)
at weblogic.jdbc.jta.DataSource.getXAConnectionFromPool(DataSource.java:1670)
at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1468)
at weblogic.jdbc.wrapper.JTAConnection.getXAConn(JTAConnection.java:199)
at weblogic.jdbc.wrapper.JTAConnection.checkConnection(JTAConnection.java:68)
at weblogic.jdbc.wrapper.Connection.preInvocationHandler(Connection.java:93)
at weblogic.jdbc.wrapper.Connection.prepareStatement(Connection.java:480)
at dave.DbExecutor.run(DbExecutor.java:24)
at java.lang.Thread.run(Thread.java:619)
,currentThread=Thread[Thread-70,5,Pooled Threads],lastUser=null,currentError=null,currentErrorTimestamp=null,JDBC4Runtime=true,supportStatementPoolable=true,needRestoreClientInfo=false,defaultClientInfo={},supportIsValid=true" back into the pool "XE".>
<Nov 27, 2010 12:22:25 PM CET> <Warning> <Common> <BEA-000620> <Forcibly releasing inactive resource "autoCommit=true,enabled=true,isXA=true,isJTS=false,vendorID=0,connUsed=false,doInit=false,'null',destroyed=false,poolname=XE,appname=null,moduleName=null,connectTime=337,dirtyIsolationLevel=false,initialIsolationLevel=2,infected=false,lastSuccessfulConnectionUse=1290856766082,secondsToTrustAnIdlePoolConnection=10,currentUser=java.lang.Exception
at weblogic.jdbc.common.internal.ConnectionEnv.setup(ConnectionEnv.java:318)
at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:344)
at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:322)
at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:438)
at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:317)
at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:93)
at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:61)
at weblogic.jdbc.jta.DataSource.getXAConnectionFromPool(DataSource.java:1670)
at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1468)
at weblogic.jdbc.wrapper.JTAConnection.getXAConn(JTAConnection.java:199)
at weblogic.jdbc.wrapper.JTAConnection.checkConnection(JTAConnection.java:68)
at weblogic.jdbc.wrapper.Connection.preInvocationHandler(Connection.java:93)
at weblogic.jdbc.wrapper.Connection.prepareStatement(Connection.java:480)
at dave.DbExecutor.run(DbExecutor.java:24)
at java.lang.Thread.run(Thread.java:619)
,currentThread=Thread[Thread-116,5,Pooled Threads],lastUser=java.lang.Throwable,currentError=null,currentErrorTimestamp=null,JDBC4Runtime=true,supportStatementPoolable=true,needRestoreClientInfo=false,defaultClientInfo={},supportIsValid=true" back into the pool "XE".>



Connection Pool Diagnostics

Inactive Connection Timeout

No comments:

Post a Comment