Class ConnectionPoolHealthSqlInterceptor

java.lang.Object
com.atlassian.jira.ofbiz.ConnectionPoolHealthSqlInterceptor
All Implemented Interfaces:
org.ofbiz.core.entity.jdbc.interceptors.connection.SQLConnectionInterceptor, org.ofbiz.core.entity.jdbc.interceptors.SQLInterceptor

public class ConnectionPoolHealthSqlInterceptor extends Object implements org.ofbiz.core.entity.jdbc.interceptors.connection.SQLConnectionInterceptor
An interceptor for SQL connection use that will keep track of how many connections each thread uses and report warnings for various things that could cause trouble, like a single thread requesting multiple connections from the pool.

We log a warning or error message when:

  • A thread requests LIMIT connections at once for the first time since it was last reset, where LIMIT is normally 3, but becomes 2 if in STRICT_MODE.
  • A thread requests multiple connections while the connection pool is in the DANGER_ZONE.
  • One of the preceding events has occurred and the thread is releasing one of the connections that had been obtained before one of the above log messages had been triggered. The idea is that these did not get logged on the way in, but it may be important to see where the outer connections came from, and hopefully the code that releases the connection is located near whatever allocated it. This is a workaround for the fact that creating a stack trace for everything just-in-case is too expensive.
Since:
v7.0.0
  • Field Details

    • DANGER_ZONE

      public static final String DANGER_ZONE
      The minimum number of connections that must still be available for it to be considered safe to request a second connection. Outside of STRICT_MODE, we would normally only log when 3 or more connections are requested at once; however, if the pool is within the "danger zone" of being exhausted, then even requesting just 2 connections is considered as a deadlock risk.

      Default: 2

      See Also:
    • QUIET

      public static final String QUIET
      Forces all logging to be at the debug level instead of the warning level.
      See Also:
    • STRICT_MODE

      public static final String STRICT_MODE
      Lowers the threshold of what constitutes "too many connections" from 3 to 2 so that we can be even more aggressive in tracking down code that consumes multiple connections. Be forewarned that there are known places where multiple connections are deliberately used at times, such as when indexing issues, creating an issue, or populating an ID bank for OfBiz, so the signal-to-noise ratio may be disappointing.

      Default: false

      See Also:
  • Constructor Details

    • ConnectionPoolHealthSqlInterceptor

      public ConnectionPoolHealthSqlInterceptor()
  • Method Details

    • onConnectionTaken

      public void onConnectionTaken(Connection connection, org.ofbiz.core.entity.jdbc.interceptors.connection.ConnectionPoolState connectionPoolState)
      Specified by:
      onConnectionTaken in interface org.ofbiz.core.entity.jdbc.interceptors.connection.SQLConnectionInterceptor
    • onConnectionReplaced

      public void onConnectionReplaced(Connection connection, org.ofbiz.core.entity.jdbc.interceptors.connection.ConnectionPoolState connectionPoolState)
      Specified by:
      onConnectionReplaced in interface org.ofbiz.core.entity.jdbc.interceptors.connection.SQLConnectionInterceptor
    • beforeExecution

      public void beforeExecution(String sqlString, List<String> parameterValues, Statement statement)
      Specified by:
      beforeExecution in interface org.ofbiz.core.entity.jdbc.interceptors.SQLInterceptor
    • afterSuccessfulExecution

      public void afterSuccessfulExecution(String sqlString, List<String> parameterValues, Statement statement, ResultSet resultSet, int rowsUpdated)
      Specified by:
      afterSuccessfulExecution in interface org.ofbiz.core.entity.jdbc.interceptors.SQLInterceptor
    • onException

      public void onException(String sqlString, List<String> parameterValues, Statement statement, SQLException sqlException)
      Specified by:
      onException in interface org.ofbiz.core.entity.jdbc.interceptors.SQLInterceptor