What does the message "Closing a connection for you" mean?
It means you are not closing your connections to return them to the pool. To avoid connection leaks you should have code like the following:
Connection connection = dataSource.getConnection(); try { // DO WORK } finally { try { connection.close(); } catch (Throwable ignored) { } }
For jdbc you should do the same thing for Statements and ResultSets. Normally Statements are closed when the Connection is closed, but connection pooling means the close does not happen. Similarly, if you have prepared statements in a cache, ResultSets need to be closed.
Thread Local Patterns
Many persistent frameworks (hibernate/ojb) open and close connections "at random". i.e. As far as JBoss is concerned it looks like one ejb allocated the connection and another closed
it.
The connection close checking does not understand this behaviour. It expects the
same ejb that allocated the connection to also close it.
If you use such a pattern, you can turn off this message (see below) but you are on
your own when it comes to detecting connection leaks. From 3.2.6 there is a
"listInUseConnections" on the CachedConnectionManager.
However, there is this known issue with some transacion demarcation semantics.
This is not really a JBoss use, more that
ThreadLocal
patterns bypass J2EE semantics.
If you do hit the problem removing the
CachedConnectionInterceptor
from the
conf/standardjboss.xml will workaround the spurious message. You can trust hibernate at least
to close connections properly provided you are ending user transactions correctly.
Turning off Connection Close Checking
In production you don't need this checking. Hopefully you have found all the connection leaks during development. You can turn it off on the CachedConnectionManager.
transaction-service.xml for 3.2.x
jbossjca-service.xml for 4.x
Change "Debug" to false.
<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">false</attribute>
Related
CanJBossTellMeWhenIDontCloseAConnection?
Comments