WebSphere database StaleConnectionException purge policy

Home > Search
  by

A StaleConnectionException occurs when a connection to a database besomes stale. Typically, a stale connection is caused by:

  • Some issue with the database, such as the database stopped running.
  • Some issue with the application code, such as a sql object requested after database close() was called.
  • Some issue with the JDBC.

 

The purge policy tells WebSphere what to do when a stale connection or fatal connection error is detected.

  1. In the left panel of the web console, expand Resources > JDBC > Data sources.
  2. Select a data source.
  3. Select Connection pool properties.

The image below displays the default connection pool properties for a data source. The purge policy drop-down has two options, EntirePool or FailingConnectionOnly.

 

With EntirePool, all database connections are destroyed, so connections that are needed will need to be reestablished to the database. There is a possibility that some valid connection may be mistakenly closed, but this is unlikely.

With FailingConnectionOnly, only database connections that have the StaleConnectionException are closed, which eliminates the possibility of closing a valid connection. There are some possible issues with this, such as subsequent connections be mistakenly flagged as stale instead of valid. For this reason, EntirePool is usually the preferred option.

Changes made to the purge policy may improve the response time of an application.

 


Handling stale exceptions in Java

Stale exceptions can also be handled in Java, which allows an application to quickly recover from a StaleConnectionException.

catch(java.sql.SQLException sqlX)
 {
   // If StaleConnectionException is detected
   if (com.ibm.websphere.rsadapter.WSCallHelper
       .getDataStoreHelper(ds)
       .isConnectionError(sqlX))
   {
     // Do something here to address the stale connection
   }
  }

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments