Using a stale connection checker in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6
- 7
- All Databases
Issue
- What is the purpose of the stale connection checker?
- How does the stale connection checker relate to fault tolerance?
- How is a stale connection checker specified?
Resolution
- NOTE A stale connection checker is only relevant if the application is explicitly coded to handle
org.jboss.jca.adapters.jdbc.StaleConnectionException.- If the application is not coded to handle
StaleConnectionException, a stale connection checker class should not be specified.
- If the application is not coded to handle
- The fault tolerance mechanism does not require a stale connection checker
- Stale connection checking is only used to raise errors to application code in a standard way allowing application code to recognize stale connection state issues in case application specific logic is required (often this is not necessary - since the standard approach to many types of failed "requests" is simply to retry the failing operation).
- Stale connection checker classes implement
org.jboss.jca.adapters.jdbc.spi.StaleConnectionCheckerto identify stale connection state exceptions1- Implementations of
StaleConnectionCheckerinspect datasource-type specific error codes, etc. inSQLExceptionto determine if they represent stale connection state errors - Where stale state exceptions are identified, JBoss wraps the underlying
SQLExceptioninorg.jboss.jca.adapters.jdbc.StaleConnectionExceptionbefore raising the exception to application code
- Implementations of
- A stale connection checker class may be specified within the
<validation>configuration for a datasource using
<validation>
...
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
...
</validation>
- See
<JBOSS_HOME>/docs/schema/jboss-as-datasources_1_*.xsd
Note
org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionCheckertests for:ORA-01014ORA-01033ORA-01034
- JBoss EAP ships with the following which return false for all
SQLExceptionerrors:org.jboss.jca.adapters.jdbc.extensions.db2.DB2StaleConnectionCheckerorg.jboss.jca.adapters.jdbc.extensions.novendor.NullStaleConnectionChecker
- Developers may choose to implement a custom stale connection checker class unique to their chosen datasource by implementing the
StaleConnectionCheckerclass and registering the custom classs
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.