The StaleConnectionException is issued when the database vendor issues an exception indicating that a connection currently in the connection pool is no longer valid. This can happen for many reasons, including
1. The application tries to get a connection and fails, as when the database is not started.
2. A connection is no longer usable due to a database failure. When an application tries to use a connection it has previously obtained, the connection is no longer valid. In this case, all connections currently in use by an application can get this error when they try to use the connection.
3. The application using the connection has already called close() and then tries to use the connection again.
4. The connection is orphaned (because the application had not used it in at most two times the value of the unused timeout setting) and the application tries to use the orphaned connection. This case applies only to Version 4.0 data sources.
5. The application tries to use a JDBC resource, such as a statement, obtained on a now-stale connection.
A connection is closed by the Version 4.0 data source auto connection cleanup feature and is no longer usable. Auto connection cleanup is the standard mode in which connection management operates. This mode indicates that at the end of a transaction, the transaction manager closes all connections enlisted in that transaction. This enables the transaction manager to ensure that connections are not held for excessive periods of time and that the pool does not reach its maximum number of connections prematurely. Detecting stale connections
When a connection to the database becomes stale, operations on that connection result in an SQL exception from the JDBC driver, it contains state and error code values that you can use to determine the meaning of the exception. States and error codes vary depending on the database vendor
Recovering from stale connections
Recovering from stale connections is a joint effort between the application server run time and the application developer. From an application server perspective, the connection pool is purged based on its Purge Policy setting.
Explicitly catching a Stale Connection exception makes it possible for an application to recover from bad connections. When application code catches a Stale Connection exception, it should take explicit steps to handle the exception.
ReplyDeleteThere are things in our life that is not eternal thus we stand still and never show weaknesses. This only means that we are strong enough to face everything either it is big or small. Visit my site for more good vibes and inspirational thoughts. Good day!
n8fan.net
www.n8fan.net