The CachedConnectionValve is a JBoss feature that automatically closes all JCA connections whenever a web request completes. Presumably this exists to help novice Java Enterprise programmers (a.k.a. lazy JSP scriplet knuckleheads) remember to close their JDBC connections. Unfortunately this also has the side effect of closing other JCA resources such as JMS connections.
A Troubleshooting Example
Here is an example of the kind of trouble this can cause:
The application in question needs a kind of 'real time' update screen. It's a kind of whiteboard, where multiple users will see the same information updated ever second. I decided to implement this using a JMS topic to broadcast the changes. Each browser would then subscribe to the topic using an AJAX call, then make subsequent AJAX calls to poll the JMS subscription for messages.
The design elements are:
- The server side is an EJB3 SFSB
- The browser invokes the SFSB using Seam Remoting.
- The SFSB is in the Seam conversation, which is in the HttpSession.
So, the problem with this approach was that when the system got to step
(3), the JMS connection in the conversation was always closed and the call to receive messages would fail. After looking at the logs and setting some breakpoints I found that CachedConnectionValve was iterating through the list of JCA connections and closing them all during step
(2). This of course included the JMS topic connection opened by the SFSB method.
Grepping through the configuration files lead me to this comment in <tt>jbossweb-tomcat55.sar/server.xml}}:
Disabling the CachedConnection Manager
- Find the
Valveelement for the CachedConnectionManager in
jbossweb-tomcat55.sar/server.xmland comment it out:
- Locate the Tomcat5 mbean dependency on CachedConnectionManager in
jbossweb-tomcat55.sar/META-INF/jboss-service.xmland comment it out: