Is DBCP (Apache Commons Database Connection Pooling) still relevant?

前端 未结 4 463
Happy的楠姐
Happy的楠姐 2020-12-08 22:42

The JDBC 3.0 spec talks about Connection (and Prepared Statement) pooling.

We have several standalone Java programs (i.e. we are not using an application server) tha

4条回答
  •  时光说笑
    2020-12-08 23:08

    Based on the encouragement of other posters, I attempted to eliminate DBCP and use the MySQL JDBC driver directly (Connector/J 5.0.4). I was unable to do so.

    It appears that while the driver does provide a foundation for pooling, it does not provide the most important thing: an actual pool (the source code came in handy for this). It is left up to the application server to provide this part.

    I took another look at the JDBC 3.0 documentation (I have a printed copy of something labeled "Chapter 11 Connection Pooling", not sure exactly where it came from) and I can see that the MySQL driver is following the JDBC doc.

    When I look at DBCP, this decision starts to make sense. Good pool management provides many options. For example, when do you purge unused connection? which connections do you purge? is there a hard or soft limit on the max number of connections in the pool? should you test a connection for "liveness" before giving it to a caller? etc.

    Summary: if you're doing a standalone Java application, you need to use a connection pooling library. Connection pooling libraries are still relevant.

提交回复
热议问题