How to establish a connection pool in JDBC?

前端 未结 13 2274
一个人的身影
一个人的身影 2020-11-22 02:43

Can anybody provide examples or links on how to establish a JDBC connection pool?

From searching google I see many different ways of doing this and it is rather conf

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 03:12

    In late 2017 Proxool, BoneCP, C3P0, DBCP are mostly defunct at this time. HikariCP (created in 2012) seems promising, blows the doors off anything else I know of. http://www.baeldung.com/hikaricp

    Proxool has a number of issues:
    - Under heavy load can exceed max number of connections and not return below max
    - Can manage to not return to min connections even after connections expire
    - Can lock up the entire pool (and all server/client threads) if it has trouble connecting to the database during HouseKeeper thread (does not use .setQueryTimeout)
    - HouseKeeper thread, while having connection pool lock for its process, requests the Prototyper thread to recreate connections (sweep) which can result in race condition/lockup. In these method calls the last parameter should always be sweep:false during the loop, only sweep:true below it.
    - HouseKeeper only needs the single PrototypeController sweep at the end and has more [mentioned above]
    - HouseKeeper thread checks for testing of connections before seeing what connections may be expired [some risk of testing expired connection that may be broken/terminated through other timeouts to DB in firewall, etc.]
    - The project has unfinished code (properties that are defined but not acted upon)
    - The Default max connection life if not defined is 4 hours (excessive)
    - HouseKeeper thread runs every five seconds per pool (excessive)

    You can modify the code and make these improvements. But as it was created in 2003, and updated in 2008, its lacking nearly 10 years of java improvements that solutions like hikaricp utilize.

提交回复
热议问题