I'm creating connection manager class that would return java.sql.Connection
to the customers of the class.
My goal is to always have 2 available connections in pool so I wouldn't loose time for creating connections. When I return the available connection, I need to make Oracle UCP create new available connection, so it would be always 2 connections available.
The problem is Oracle UCP doesn't have an option to control it. I've read the UCP documentation, but hadn't found any solution.
There is setMinPoolSize()
method, but it controls available + borrowed connections, not only the available ones.
Also there is a harvestable connection functionality, but it harvests existing (borrowed) connections instead of creating new.
Note:
I'm using Oracle 11.2.0.3 and the latest ucp.jar
(for Oracle 11.2.0.3)
There is no such solution. When a connection is requested from a connection pool, it is either checked out from the pool, or a new connection is created. The cost of this is incurred on the Thread that does the request. If you would always want to maintain 2 more connections in the pool than in use, you are simply moving the problem: when a connection is checked out and available < 2
then a Connection will be added. The cost incurred once again on the Thread requesting the connection (yes in theory this could be offloaded to a separate thread/executor, but that would complicate the pool).
A connection pool is intended to reduce the cost of creating connections, by keeping the connection available for re-use and thus 'spreading the cost', it is not intended to do away with the cost entirely.