A ConnectionWaitTimeout exception will occur when there is a request to make a connection to a database, all of the connections in the connection pool are being used, and the timeout period has been exceeded.
- In the left panel of the web console, expand Resources > JDBC > Data sources.
- Select a data source.
- Select Connection pool properties.
In this example, the maximum number of connections is 10 and the timeout is 180 seconds. Let's say all 10 connections in the connection pool are being used. When there are additional requests to connect to the database, WebSphere will monitor the requests to see if the requests reach the timeout. If the connection request reaches the timeout period, a ConnectionWaitTimeout exception will occur.
Don't abuse Maximum connections
You may ask yourself, why would we ever want to limit the maximum connections? In an enterprise setting, you may find yourself in a situation where you have hundreds or possibly even thousands of different data sources, each with their own connection pool. If you were not to limit the maximum connections in each connection pool, the database could become overloaded with requests. This is why each connection pool limits the number of simultaneous connections that can be made to the database.
If you have multiple data sources connecting to the same backend database, you will need to be careful not to overload the backend database. For example, if you have 10 data sources with a maximum connections of 50, this creates a maximum of 500 possible connects to the same backend database, which may overload the database, or reduce the performance of the database. It is generally a good idea to set the maximum allowed connections to be less than the maximum threads of a web container.
Next, you'll want to know if 10 connections to the database is an appropriate value. In the WebSphere admin console, navigate to Monitoring and Tuning > Performance viewer > Current activity > select an application server. At the viewer, select JDBC Connection Pools and then select View Modules. In this example, the red line indicates there are 2 connections to the database, thus a maximum of 10 should be perfectly OK.
Disable the timeout
Setting the connection timeout to 0 will disable the timeout, which means that each connection will continue indefinitely and will never produce a ConnectionWaitTimeout exception will occur. This is almost always a bad idea.