Saturday August 24, 2002

Upgrading from Tyrex 0.9.7 to Commons DBCP. I'm trying to upgrade from Tyrex 0.9.7 (ships with Tomcat 4.0.4 for connection pooling) to the Commons DBCP (ships with Tomcat 4.1.x for connection pooling). I've set it up according to these instructions. However, my connections don't seem to be getting closed, or it's closing the connection pool and I get a "connection is closed" error.
If I use this method to close connections, I get "connection is closed:"
/** Closes a connection from the connection pool */
public void closeConnection(Connection con) throws ServiceLocatorException
{
try {
con.close();
} catch (SQLException sqle) {
logger.error("SQLException: " + sqle.getMessage());
throw new ServiceLocatorException(sqle);
} finally {
if (con != null) {
// try again
try {
con.close();
} catch (SQLException csqle) {
// ignore
}
}
}
}
I changed my closeConnection method (see below). It seems to work better (no closed connection error), but I am wondering about the open connections to mysql. When I monitor them (show status; watch Threads_connected), there are 3 at first (I'm guessing from my monitor connection, JDBCRealm and Connection pool). It gets up to 5, any tips on how I can tell if connection pooling is working?
/** Closes a connection from the connection pool */
public void closeConnection(Connection con) throws ServiceLocatorException
{
try {
con.close();
} catch (SQLException sqle) {
logger.error("SQLException: " + sqle.getMessage());
throw new ServiceLocatorException(sqle);
} finally {
// try again
try {
if (!con.isClosed()) {
con.close();
}
} catch (SQLException csqle) {
// ignore
}
}
}
I think the problem is that it's not creating a "pooled" connection. When you are using a connection pool, con.close() should just return it, not actually close it - right?
In my getPooledConnection method, I'm getting "Non-Pooled Connection" each time.
/**
* Retrieves a connection from the connection pool
*/
public Connection getPooledConnection() throws ServiceLocatorException
{
try {
ds = (DataSource) getEnvContext().lookup(Constants.JNDI_DB);
} catch (NamingException ex) {
logger.error("NamingException: " + ex.getMessage());
throw new ServiceLocatorException(ex);
}
try {
if (ds instanceof ConnectionPoolDataSource) {
ConnectionPoolDataSource poolDataSrc = (ConnectionPoolDataSource) ds;
PooledConnection pc = poolDataSrc.getPooledConnection();
con = pc.getConnection();
if (logger.isDebugEnabled()) {
logger.debug("Pooled Connection");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Non-Pooled Connection");
}
con = ds.getConnection();
}
} catch (SQLException ex) {
logger.error("SQLException: " + ex.getMessage());
throw new ServiceLocatorException(ex);
}
return con;
}
If you have a WAG/suggestion, please enlighten me! Posted in Java at Aug 24 2002, 04:12:15 AM MDT Add a Comment
Problems with UserTransaction/Tomcat on OS X I'm having some problems getting a "UserTransaction" to work in a Struts Action on Tomcat 4.0.4 in OS X with JDK 1.3. The same code works fine on Windows XP/Red Hat Linux 7.2-.3 with JDK 1.4. Maybe it's a JDK 1.3 issue? Any suggestions/tips are appreciated. Posted in Mac OS X at Aug 24 2002, 04:01:36 AM MDT Add a Comment
Search This Site
Recent Entries
- My TSSJS 2010 Presentations and Summary
- What's New in Spring 3.0
- Developing Rich Web Service APIs with Java
- C++, Java and .NET: Lessons Learned from the Internet Age
- Highly Interactive Software with Java and Flex
- The Cloud Computing Continuum with Bob McWhirter
- Software Quality: The Quest for the Holy Grail?
- What's Happening in the Java World?
- Fantastic Fun in Jackson Hole
- How We Hired a Team of 10 in 2 Months