Validate connections

The advantage of setting this configuration is that an invalid connection will never be used, and it helps us to prevent client errors. The disadvantage of this configuration is a small performance penalty because to validate the connection, one round-trip to the database is required to check whether the session is still active. The validation is accomplished via sending a small query to the server, but the cost of this query could be lower.

The configuration parameters for validating connections are as follows:

  • testOnBorrow: When the testOnBorrow attribute is defined as true, the connection object is validated before use. If it fails to validate, it will be dropped into the pool, and another connection object will be chosen. Here, we need to make sure that the validationQuery attribute is not null; otherwise, there is no effect on configuration. 
  • validationInterval: The validationInterval attribute defines the frequency of the validating connection. It should not be more than 34 seconds. If we set a larger value, it will improve the application performance, but will also increase the chances of a stale connection being present in our application.
  • validationQuery: The SELECT 1 PostgreSQL query is used to validate connections from the pool before sending them to serve a request.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset