c3p0 connection pool without testing on either check-in or check-out

半城伤御伤魂 提交于 2021-02-10 15:51:45

问题


From the c3p0 documentation:

For some applications, high performance is more important than the risk of an occasional database exception. In its default configuration, c3p0 does no Connection testing at all. Setting a fairly long idleConnectionTestPeriod, and not testing on checkout and check-in at all is an excellent, high-performance approach.

If I understand the meaning of the c3p0 configuration properties correctly, if the database becomes unavailable for a short period of time and then recovers (e.g. it is restarted or a network issue appears), and if there is a fairly high usage of the connections which are pooled in the c3p0 so that no connection is idle longer than idleConnectionTestPeriod, then none of those connections would ever be tested for validity and all attempts to use them would be unsuccessful. Basically, the connection pool would not automatically recover from the db unavailability.

Is it just bad wording in the documentation stating that this is an excellent, high-performance approach without a warning that the connection pool loses the ability to auto-recover from invalid connections, or I have misunderstood the meaning of the relevant configuration properties?


回答1:


Huh. I wrote that, probably more than a decade ago, and you are right, it isn't good advice. Originally, Connection testing in c3p0 was often very expensive (because for dbms/driver independence and certainty of a full validity test, it used an expensive metadata getTables(...) test), and I strongly advised people to make sure to test asynchronously, in checkins and idle tests. Once preferredTestQuery and then jdbc4 Connection.isValid() made efficient reliable testing possible, I revised the docs to remove the discouragement of synchronous checks. But apparently this stayed, and it is bad advice even for the old days. In practice, if you are not testing during checkout, I recommend both async tests on checkin and idle tests, and moderately frequent idle tests (30 seconds-ish) usually, to reduce the likelihood an application sees stale Connections and the delay before Connections get refreshed after an outage.

I'll revise this going forward. Thanks for the catch.



来源:https://stackoverflow.com/questions/44807078/c3p0-connection-pool-without-testing-on-either-check-in-or-check-out

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