Usage of DBCP connection pool TestOnBorrow

The production environment connection pool TestOnBorrow is set to false, resulting in sometimes unavailable connections. analyse as below:

  • When TestOnBorrow=false, since the availability of the connection in the pool is not detected, if the connection in the connection pool is closed by the database, the application may obtain these unavailable connections when it getsConnection through the connection pool, and if these connections are not used by other If the threads are recycled, they will not be abolished by the connection pool, nor will they be re-created, occupying the quota of the connection pool.

The last packet successfully received from the server was 19,956 milliseconds ago.  The last packet sent successfully to the server was 32 milliseconds ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1571)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3143)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3597)
    ... 8 more

  • When TestOnBorrow=true, there are two cases:

① When an instance of the cluster is down, if the connection is not in the communication stage, the tcp connection is in the CLOSE_WAIT state or has been closed. When the application getsConnection through the connection pool, the connection will be detected when borrowing. Since the connection has been closed, the report is as follows An error is reported, and a new connection is re-established. At this time, the new connection is connected to other instances of the cluster. Communication is normal after that.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3143)
    at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:597)
    ... 21 more


② When an instance of the cluster goes down, if the connection happens to be in the communication stage, since the client cannot immediately sense that the server has been disconnected, it may report the following error, waiting for the server's response to timeout and report an error. When the application getsConnection through the connection pool, the connection will be detected when borrowing. Since the connection has been closed, the following error is reported, and a new connection is re-established. At this time, the new connection is connected to other instances of the cluster. Communication is normal after that.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 10,538 milliseconds ago.  The last packet sent successfully to the server was 10,306 milliseconds ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326573172&siteId=291194637