Tomcat Configuration using DBCP

流过昼夜 提交于 2019-12-02 17:46:07
Alain Pannetier

Since DBCP keeps returned mysql connections open for upcoming connection requests, they fall victims to the MySQL Server timeout.

DBCP has a number of features that can help (can be used starting with Tomcat 5.5 IIRC).

validationQuery="SELECT 1"
testOnBorrow="true"

The validation makes sure that a connection is valid before returning it to a webapp executing the 'borrow' method. The flag of course, enables this feature.

If the timeout (8 hours I believe) is elapsed and the connection is dead, then a new connection is tested (if there are none anymore, it is created) and provided to the webapp.

Other possible approaches:

  1. use the testWhileIdle="true" DBCP in your resource settings to also check idle connections before an effective request is detected.

  2. Use the 'connectionProperties' to harden your MySQL connection (e.g. autoReconnect/autoReconnectForPools=true)

DBCP is not meant for use in production, even the authors say that (see this presentation: http://www.infoq.com/presentations/Tuning-Tomcat-Mark-Thomas).

I suggest taking a look at C3P0: http://www.mchange.com/projects/c3p0/index.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!