Need Code to create Connection Pool in java

后端 未结 10 1687
轻奢々
轻奢々 2020-11-30 20:50

Need code to create the connection pool in java? How does we make sure that connection pool doesn\'t return the same object which is already in use? How happens if client cl

10条回答
  •  被撕碎了的回忆
    2020-11-30 21:28

    Need code to create the connection pool in java?

    Not sure what the question is but don't create yet another connection pool, use an existing solution like C3P0, Apache DBCP, Proxool or BoneCP (a new player in that field). I would use C3P0.

    How does we make sure that connection pool doesn't return the same object which is already in use?

    Because if a connection has been borrowed from the pool and not returned yet, it's just not in the pool and can't be assigned to another client of the pool (resources are removed from the pool until they are returned).

    How happens if client closed the connection after taking it out from Connection pool?

    The connection a client gets from a pool is not really a java.sql.Connection, it's a wrapper (a proxy) for a java.sql.Connection that customizes the behavior of some methods. The close() method is one of them and does not close the Connection instance but returns it to the pool.

提交回复
热议问题