Chapter 3. Servlet Container

There are two main configuration parameters that have a direct effect on performance and scalability: cached connection manager and HTTP session replication.

3.1. Cached Connection Manager

The Cached Connection Manager is used for debugging data source connections and supporting lazy enlistment of a data source connection in a transaction, tracking whether they are used and released properly by the application. At the cost of some overhead, it can provide tracing of the usage, and make sure that connections from a data source are not leaked by your application. Although that seems like an advantage, in some instances it's considered an anti-pattern and so to be avoided. If you are using bean managed transactions (BMT), it allows you to do the following (shown in pseudo-code):
Connection connection = dataSource.getConnection();
transaction.begin();
<Do some work>
transaction.commit();
Instead of:
transaction.begin();
Connection connection = datasource.getConnection();
<Do some work>
transaction.commit();
The first option is very useful for debugging purposes but should not be used in a production environment. In the default, standard and all configurations, the CachedConnectionManager is configured to be in the servlet container in debug mode. It's also configured in the production configuration but with debug mode off. If you do not use BMT, and/or you do not have the anti-pattern, described earlier, it's best to remove the CachedConnectionManager. The configuration is in the file server.xml in the directory JBOSS_EAP_DIST/jboss-as/server/<PROFILE>/deploy/jbossweb.sar. Note that the minimal configuration does not include JBoss Web.
Below is an extract from server.xml in which the CachedConnectionManager is enabled.
<!-- Check for unclosed connections and transaction terminated checks in servlets/jsps.
Important: The dependency on the CachedConnectionManager in META-INF/jboss-service.xml must be uncommented, too -->
<Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
   cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
   transactionManagerObjectName="jboss:service=TransactionManager" />
To disable the CachedConnectionManager, comment the last three lines, as per the following example:
<!-- Check for unclosed connections and transaction terminated checks in servlets/jsps.
Important: The dependency on the CachedConnectionManager in META-INF/jboss-service.xml must be uncommented, too
<Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
                           cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
                           transactionManagerObjectName="jboss:service=TransactionManager" />
-->
Another configuration file also needs to be edited: jboss-beans.xml in the JBOSS_EAP_DIST/jboss-as/server/<PROFILE>/deploy/jbossweb.sar/META-INF directory. Note that the minimal configuration does not include JBoss Web. This file is used by the micro-container for JBoss Web’s integration with it, and it specifies the connections between the dependent components. In this case, the CachedConnectionManager’s valve is dependent on the transaction manager. So, in order to get rid of the valve properly, we have to remove the dependency information from this configuration file. The pertinent information is at the top of the file, and it looks like the following:
<!-- Only needed if the org.jboss.web.tomcat.service.jca.CachedConnectionValve
         is enabled in the tomcat server.xml file.
    -→
    <depends>jboss.jca:service=CachedConnectionManager</depends>
<!-- Transaction manager for unfinished transaction checking in the CachedConnectionValve -->
<depends>jboss:service=TransactionManager</depends>
Comment these lines as in the following example:
<!-- Only needed if the org.jboss.web.tomcat.service.jca.CachedConnectionValve
           is enabled in the tomcat server.xml file.
      -→
      <!--<depends>jboss.jca:service=CachedConnectionManager</depends> -→
      <!-- Transaction manager for unfinished transaction checking in the CachedConnectionValve -->
<!--<depends>jboss:service=TransactionManager</depends>-->
When editing XML, comments cannot be nested so it's important to get this correct. Refer to the section on the EJB 3 container for instructions on removing the CachedConnectionManager from there.