Why does an application running on WebSphere Application Server receive a ConnectionWaitTimeoutException?

Technote (FAQ)
Problem
The exception com.ibm.ejs.cm.pool.ConnectionWaitTimeoutException indicates that the
application timed out while waiting to receive a connection from the pool. This occurs when the connection pool reaches its maximum size, all connections are in use, and the connection timeout parameter expires. In addition, there are no connections currently in use that the application can share, because either the user name and password are different or it is in a different transaction.
Solution
There are two ways to avoid the problem:
  1. The WebSphere® administrator reviews the expected usage of the application and tunes the WebSphere data source and the database accordingly. The maximum connection pool size must be large enough to handle the maximum number of concurrent users expected by the application. The connection timeout can also be increased to allow an application to wait longer before the request for a connection times out.

  2. The application developer ensures that under all circumstances, including exceptions, all JDBC™ resources are closed and released when they are finished being used. This includes connections, statements, and result sets. Failing to close and release JDBC resources can cause long waits for connections, and the timeout might be reached, causing the ConnectionWaitTimeoutException to be issued. Although a connection left unclosed eventually is reaped and returned to the pool by WebSphere after the idle or orphan timeout is reached, closing all connections is a best practice and helps avoid connection timeouts.

The following code example demonstrates the proper way to close connections, statements, and result sets:


Connection con = null;
ResultSet rs = null;
PreparedStatement ps = null;
try
{
con = ds.getConnection(USERID,PASSWORD);
ps = con.prepareStatement("SELECT * FROM SCHEMA.TABLE WHERE KEY = ?");
ps.setString(1,key);
rs = ps.executeQuery();
rs.close();
ps.close();
con.close();
}
catch (Throwable t)
{
// Insert Appropriate Error Handling Here
}
finally
{
// The finally clause is always executed - even in error
// conditions JDBC objects will always be closed

try
{
if (rs != null)
rs.close();
}
catch(Exception e) {}

try
{
if (ps != null)
ps.close();
}
catch(Exception e) {}

try
{
if (con != null)
con.close();
}
catch (Exception e){}
}
}











Document Information

Product categories: Software, Application Servers, Distributed Application & Web Servers, WebSphere Application Server, DB Connections/Connection Pooling
Operating system(s): Multi-Platform
Software version: 3.5, 4.0
Software edition: Edition Independent
Reference #: 1066521
IBM Group: Software Group
Modified date: 2004-09-07