Ashish Kataria Ashish Kataria - 5 months ago 15
Java Question

JBOSS AS 7.1.1.Final Closing Leaked Connections?

I have already done the following settings in standalone.xml as:

<datasource jta="true" jndi-name="java:jboss/datasources/myDS" pool-name="java:jboss/datasources/myDS" enabled="true" use-ccm="true">
<cached-connection-manager debug="true" error="true"/>


Therefore, I am also getting the messages like "Closing a connection for you" as:

INFO [org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager] (http--0.0.0.0-8080-160) IJ000100: Closing a connection for you. Please close them yourself: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@5cdb81dc: java.lang.Throwable: STACKTRACE
at org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl.registerConnection(CachedConnectionManagerImpl.java:265)
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:495)
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)


Still, Sometimes my pool gets exhausted. It runs out of connections beyond 200 as defined. Why?

<min-pool-size>30</min-pool-size>
<max-pool-size>200</max-pool-size>


There is no way, that my application needs these much connections.
There is surely a connection leakage. And If it is, Why jboss is not closing it by it's own when I have enabled the setting as i said above:

<datasource jta="true" jndi-name="java:jboss/datasources/myDS" pool-name="java:jboss/datasources/myDS" enabled="true" use-ccm="true">
<cached-connection-manager debug="true" error="true"/>


How to resolve?

Thanks.

Answer

JBoss can not close all leaked connection.

You need to find leaked connection by checking logs after enabling JCA logging. I resolved connection leak by this way.

<logger category="org.jboss.jca">
                <level name="DEBUG"/>
</logger>

You will get entries like below in logs

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: getConnection(null, null) [1/100] --> It means taking connection from pool.

DEBUG [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (MSC service thread 1-4) {JNDI_NAME}: returnConnection(607e334, false) [1/99] --> It means returning connection to pool

You can check which query is not returning connetion to pool and check your application from where that query is being executed. Fix it.

Comments