Search This Blog

Tuesday, October 20, 2009

Application server connection pool settings that are of concern to the Software Architect:Shared Connections

IBM Websphere: 'Shared Connections' is the setting in Websphere Application Server by default and, at least in my experience, is a setting that is little known about -- and, depending on your application -- can have a major impact on your design.

What it means is that the same connection is shared by all J2EE components during an HTTP request. At least that is what I think it means. However, I do know for sure the practical result of this setting..

Say you have a Servlet/Struts action or whatever server side component that gets executed to service an HTTP request: (not intended to be working code).

public void doGet(HttpServletRequest req, HttpServletResponse resp) {

java.sql.Connection conn = null;
try {
dataSource.getConnection();
... do stuff...
}
finally {
conn.close():
}
.. do some other stuff, perhaps a call to a backend service..then
req.getRequestDispatcher("some.jsp").forward(req,resp);
}

You may (understandably) believe that the connection is returned to the pool, right after you called Connection.close(). However, if the Connection Pool is set to 'Shared' (the default), you would be wrong. Websphere will hold onto the connection through the call to the backend service and until it finishes servicing the http request.

So, if you have an Application that has the above pattern -- you should definitely consider changing the datasource setting from 'Shareable' to 'Unshareable'.

You do this in the web deployment descriptor. Reference tab in the Websphere Administrative console.. or:




jdbc/ds1
javax.sql.DataSource
Container
Unshareable

No comments:

Post a Comment