Question & Answer
Question
This technote describes the steps that are needed in order to enable JDBC connection pool testing in WebSphere.
Answer
Background
TeamWorks uses pooled JDBC database connections from the app server. When the connection to your database fails, pooled connections that are no longer valid might exist in the free pool. Connection pretesting is a way to test connections from the free pool before giving them to the client. You can enable the PreTest Connections feature in the WebSphere administrative console to help prevent TeamWorks from obtaining connections that are no longer valid.
The feature is particularly useful for routine database outages. Because these outages are usually scheduled for periods of low use, connections to the database are likely to be in the free pool rather than in active use. Active connections are not pretested; pretesting impedes performance during normal operation.
Note that if connection pretesting is not enabled and TeamWorks attempts to use an invalid connection you will likely see an exception like this:
com.ibm.websphere.ce.cm.StaleConnectionException: Io exception: Broken pipe
How to enable database connection testing in WebSphere
To have WebSphere automatically check the validity of a connection when serving it up from the connection pool do the following:
- Enable and configure connection pretesting.
- Open the j2c.properties file. The file is located in install_root/properties/j2c.properties.
- Using the example in the file, create an <advanced connection properties> entry corresponding to your datasource.
- Enable connection pretesting
- Set <testConnection> to true.
- Specify how often to retry, should the pretest fail.
- Set <testConnectionRetryInterval> to the number of seconds for the pretest connection thread to wait between attempts to create and pretest a connection. It will do so until it is successful, at which point the connection pool starts processing getConnection() requests and the pretest connection thread ends.
- If the pretest fails, new connection requests are rejected with a ResourceAllocationException indicating Failed preTestConnection. Pool requests are blocked until the test connection thread is successful.
- For example, this j2c.properties configuration enables connection pretesting to occur every 5 seconds until it is successful:
- <advanced-connection-properties connectionFactoryJNDIName=jdbc/TeamWorksDB>
- <testConnection>true</testConnection>
- <testConnectionRetryInterval>5</testConnectionRetryInterval>
- </advanced-connection-properties>
- Add one section like the above for each datasource in question... just substitute the correct JNDI name
- Specify the SQL statement to use when connection pretesting is enabled.
- Open the administrative console.
- Navigate to Resources > JDBC_provider > Data Sources > data_source > Custom Properties.
- Specify preTestSQLString as the property name.
- Specify an SQL statement as the property value.
- Note that you should use the LEAST expensive SQL possible to verify the connection (i.e."select 1 from dual" in oracle or "SQL select 1" in SQL Server.)
For WebSphere 5.1:
Here is a link to IBM's web site with some additional information on WebSphere 5.1:
Configure a preTestSQLString custom property for the data source.
For WebSphere 6.0.x
- In the administrative console, click Resources > JDBC providers.
- Select a provider and click Data Sources under Additional properties.
- Select a data source and click WebSphere Application Server data source properties under Additional properties.
- Select the PreTest Connections check box.
- Type a value for the PreTest Connection Retry Interval, which is measured in seconds. This property determines the frequency with which a new connection request is made after a pretest operation fails.
- Type a valid SQL statement for the PreTest SQL String. Use a reliable SQL command, with minimal performance impact; this statement is processed each time a connection is obtained from the free pool.
- For example, "select 1 from dual" in oracle or "SQL select 1" in SQL Server.
Historical Number
225
Product Synonym
Teamworks TW Lombardi
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21439688