CanJBossTellMeWhenIDontCloseAConnection

Can JBossAS tell me when I don't close connections, statements or resultsets?

 

Yes.

 

Connections

 

 

For connections the configuration is in deploy/transaction-service.xml

    <attribute name="Debug">true</attribute>

 

Starting with 4.0.0, the configuration is in deploy/jbossjca-service.xml

   <!-- 
     | The CachedConnectionManager is used partly to relay started UserTransactions to 
     | open connections so they may be enrolled in the new tx.
   -->
  <mbean code="org.jboss.resource.connectionmanager.CachedConnectionManager" 
         name="jboss.jca:service=CachedConnectionManager">
    <depends optional-attribute-name="TransactionManagerServiceName">jboss:service=TransactionManager</depends>

    <!-- Enable connection close debug monitoring -->
    <attribute name="Debug">true</attribute>

  </mbean>

 

The generated message look like this (JBoss 4.x):

2010-02-24 08:10:04,086 WARN [org.jboss.resource.connectionmanager.CachedConnectionManager] Closing a connection for you.  Please close them yourself: org.jboss.resource.adapter.jms.JmsSession@745889

java.lang.Throwable: STACKTRACE
        at
org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)

      ...

 

 

Note!! To have this applied to connections openned by Servlets or JSP's see below {FOOTNOTE DEF 1 1}.

 

 

 

Statements and ResultSets

 

For statements (and from 3.2.4 ResultSets) you can add the following to your -ds.xml

  <track-statements>true</track-statements>

 

 

Closing statements and ResultSets is important if you want to use prepared statement caching

and/or don't won't to leak cursors in your database.

 

 

The generated messages looks like this (JBoss 4.x):

2010-02-24 08:10:04,086 WARN  [org.jboss.resource.adapter.jdbc.WrappedConnection] Closing a result set you left open! Please close it yourself.
java.lang.Throwable: STACKTRACE
        at org.jboss.resource.adapter.jdbc.WrappedStatement.registerResultSet(WrappedStatement.java:744)

      ...

 

2010-02-24 08:10:04,102 WARN  [org.jboss.resource.adapter.jdbc.WrappedConnection] Closing a statement you left open, please do your own housekeeping
java.lang.Throwable: STACKTRACE
        at org.jboss.resource.adapter.jdbc.WrappedConnection.registerStatement(WrappedConnection.java:872)

      ...

 

 

 

 

 

Servlets and JSP {FOOTNOTE RED #1 1}

 

 

From from 3.2.4 this checking is available in the web layer.

 

 

Enable the CachedConnectionValve by uncommenting the following in deploy/jbossweb-xxx.sar/server.xml:

         <!-- Check for unclosed connections -->
        <Valve className="org.jboss.web.tomcat.tc5.jca.CachedConnectionValve"
            cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager" ></Valve>

 

NOTE: From 4.0.0 the CachedConnectionValve should be configured this way:

        <Valve className="org.jboss.web.tomcat.tc5.jca.CachedConnectionValve"
            cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
            transactionManagerObjectName="jboss:service=TransactionManager" ></Valve>

 

JBoss 4.0.0 distribution still had the previous configuration that woulld cause a NullPointerException

in CachedConnectionValve.checkTransactionComplete(CachedConnectionValve.java:198).

 

Once the valve is enabled, the CachedConnectionManager must be registered in deploy/jbossweb-xxx.sar/META-INF/jboss-service.xml.

At the end of the file, uncomment:

       <depends>jboss.jca:service=CachedConnectionManager</depends>

 

 

 

 

 

Production and Stress Testing

 

 

In production you will want to turn these off. You should have found all your leaks during development.

 

Related

 

WhatDoesTheMessageDoYourOwnHousekeepingMean?