public interface UniversalConnectionPool extends Diagnosable
There are several key objects that make up the connection pool:
Physical Pool The physical pool maintains pooled connections that can be borrowed from the pool, returned to the pool, or closed and not returned to the pool. The pool keeps track of the connections that are available (so that they can be borrowed) and connections that are in use (so they can be reaped if it is determined that they are no longer valid).
Connection Factory Adapter The connection pool must rely on
another entity to create and close connections because connection pools can pool
any type of connection. This is the responsibility of the connection
factory adapter. A connection factory adapter is tied to a specific
resource (JDBC, JCA, LDAP, and so forth). When the connection pool needs to
create a new connection, it asks the connection factory adapter to
do so. The returned connection is placed inside a
UniversalPooledConnection object that is then placed into
the connection pool. When the connection pool closes a connection, it
hands the connection to the connection factory adapter which then closes
the connection.
Pooled Connections Each pooled connection in the connection pool is
an instance of UniversalPooledConnection. The pooled connection
decorates a physical connection (created by the connection factory adapter) which
can be borrowed.
Connection Retrieval Info The connection retrieval info object is
used by the connection factory adapter to create connections. It contains
resource-specific information that the connection factory adapter uses
to create connections. For example, the JDBC connection retrieval
info object maintains the user and password that are used to create a
connection from a JDBC resource. The JCA connection retrieval info
object maintains the Subject and JCA
ConnectionRequestInfo object.
Pool Properties The pool provides some properties for users to customize the pool's behavior, such as:
Statistics The pool maintains some statistics such as:
Lifecycle A connection pool has a lifecycle. See
UniversalConnectionPoolLifeCycleState for details.
A connection pool is started by calling the start() method and
stopped by calling the stop() method. Connections may not be
borrowed until the connection pool has been started or after the pool has
been stopped (unless the pool has been started again).
| Modifier and Type | Method and Description |
|---|---|
UniversalPooledConnection |
borrowConnection(ConnectionRetrievalInfo connectionRetrievalInfo)
Gets a connection from the connection pool.
|
default java.util.concurrent.CompletionStage<UniversalPooledConnection> |
borrowConnectionAsync(ConnectionRetrievalInfo cri,
java.util.concurrent.Executor executor)
Get a connection from a pool asynchronously
|
void |
closeConnection(UniversalPooledConnection pooledConnection)
Closes the pooled connection.
|
int |
getAbandonedConnectionTimeout()
Gets the abandoned connection timeout value.
|
int |
getAvailableConnectionsCount()
Gets the number of connections that are available in the connection
pool (that is, connections in the pool that are not currently in use by
clients).
|
int |
getBorrowedConnectionsCount()
Gets the number of connections that are actively in use by clients.
|
int |
getConnectionHarvestMaxCount()
Gets the maximum number of connections that may be harvested when
the connection harvesting occurs.
|
int |
getConnectionHarvestTriggerCount()
Gets the number of available connections below which the connection
pool's connection harvesting occurs.
|
int |
getConnectionLabelingHighCost()
Obtains the cost value which identifies a connection as "high-cost"
for connection labeling.
|
int |
getConnectionRepurposeThreshold()
Gets the connection repurpose threshold for the pool.
|
ConnectionRetrievalInfo |
getConnectionRetrievalInfo()
Gets the
ConnectionRetrievalInfo object which contains
user and password information to create the connections. |
int |
getConnectionValidationTimeout()
Connection validation timeout getter
This property changes the allowed time for a connection valiadation.
|
java.time.Duration |
getConnectionWaitDuration()
Gets the maximum time (in java.time.Duration) that any connection borrow request
can wait before it returns to the application.
|
int |
getConnectionWaitTimeout()
Deprecated.
|
int |
getHighCostConnectionReuseThreshold()
Obtains the high-cost connection reuse threshold property
value for connection labeling.
|
int |
getInactiveConnectionTimeout()
Gets the inactive connection timeout value.
|
int |
getInitialPoolSize()
Gets the initial pool size.
|
UniversalConnectionPoolLifeCycleState |
getLifeCycleState()
Gets the life cycle state of the connection pool.
|
int |
getLoginTimeout()
Gets the default maximum time in seconds that a driver will wait while attempting
to connect to a database once the driver has been identified.
|
int |
getMaxConnectionReuseCount()
Gets the maximum connection reuse count property value.
|
long |
getMaxConnectionReuseTime()
Gets the maximum connection reuse time property value.
|
int |
getMaxConnectionsPerService()
Gets the maximum number of connections that can be obtained to a particular
service, in a shared pool.
|
int |
getMaxPoolSize()
Gets the maximum number of connections that the connection pool
maintains.
|
int |
getMinPoolSize()
Gets the minimum number of connections that the connection pool
maintains.
|
java.lang.String |
getName()
Gets the name of the connection pool.
|
int |
getSecondsToTrustIdleConnection()
Gets the seconds To Trust Idle Connection value which determines whether
or not connection validation on borrow should be skipped
See property description in
setSecondsToTrustIdleConnection(). |
boolean |
getShardingMode()
Returns the mode of UCP when UCP is using a Sharded Database.
|
UniversalConnectionPoolStatistics |
getStatistics()
Gets the statistics of the connection pool.
|
int |
getTimeoutCheckInterval()
Gets the frequency (in seconds) to enforce the timeout properties.
|
int |
getTimeToLiveConnectionTimeout()
Gets the maximum time (in seconds) a connection may remain in-use.
|
boolean |
getValidateConnectionOnBorrow()
Returns whether or not a connection being borrowed should first be
validated.
|
boolean |
isReadOnlyInstanceAllowed()
Returns true if the connection borrow is allowed to a read-only instance,
false otherwise.
|
boolean |
isShareable()
Returns whether the pool is shareable or not.
|
void |
purge()
Removes all connections from the connection pool.
|
void |
reconfigure(java.util.Properties props)
Allows a connection pool to be reconfigured gracefully with a
different set of properties that specify the behavior of the
connection pool at runtime.
|
void |
recycle()
Allows only invalid available connections
in the pool to be replaced with new/fresh connections.
|
void |
refresh()
Allows connections in the pool, both borrowed and available ones,
to be replaced with new/fresh connections.
|
void |
registerConnectionAffinityCallback(ConnectionAffinityCallback cbk)
Registers a
ConnectionAffinityCallback objet on the
connection pool. |
void |
registerConnectionLabelingCallback(ConnectionLabelingCallback cbk)
Registers a
ConnectionLabelingCallback object with this
connection pool. |
void |
removeConnectionAffinityCallback()
Removes the
ConnectionAffinityCallback object registered on
the connection pool. |
void |
removeConnectionLabelingCallback()
Removes the
ConnectionLabelingCallback object registered
with this connection pool, if any. |
void |
returnConnection(UniversalPooledConnection pooledConnection)
Returns a connection back into the connection pool.
|
void |
setAbandonedConnectionTimeout(int abandonedConnectionTimeout)
Sets the abandoned connection timeout.
|
void |
setConnectionHarvestMaxCount(int connectionHarvestMaxCount)
Sets the maximum number of connections that may be harvested when
the connection harvesting occurs.
|
void |
setConnectionHarvestTriggerCount(int connectionHarvestTriggerCount)
Sets the number of available connections below which the connection
pool's connection harvesting occurs.
|
void |
setConnectionLabelingHighCost(int highCost)
Sets the cost value which identifies a connection as "high-cost" for
connection labeling.
|
void |
setConnectionRepurposeThreshold(java.lang.Integer threshold)
Sets the connection repurpose threshold for the pool.
|
void |
setConnectionRetrievalInfo(ConnectionRetrievalInfo cri)
Sets the
ConnectionRetrievalInfo for creating the initial
connections (physical connections) in the pool based on the
initialPoolSize property. |
void |
setConnectionValidationTimeout(int connectionValidationTimeout)
Connection validation timeout setter
This property changes the allowed time for a connection valiadation.
|
void |
setConnectionWaitDuration(java.time.Duration waitDuration)
Configures how much time a connection request call may wait before it either
successfully returns a connection or throws an exception.
|
void |
setConnectionWaitTimeout(int waitTimeout)
Deprecated.
|
void |
setHighCostConnectionReuseThreshold(int threshold)
Sets the high-cost connection reuse threshold for connection labeling.
|
void |
setInactiveConnectionTimeout(int inactiveConnectionTimeout)
Sets the inactive connection timeout.
|
void |
setInitialPoolSize(int initialPoolSize)
Sets the initial pool size.
|
void |
setLoginTimeout(int seconds)
Sets the default maximum time in seconds that a driver will wait while attempting
to connect to a database once the driver has been identified.
|
void |
setMaxConnectionReuseCount(int maxConnectionReuseCount)
Sets the maximum connection reuse count property.
|
void |
setMaxConnectionReuseTime(long maxConnectionReuseTime)
Sets the maximum connection reuse time property.
|
void |
setMaxConnectionsPerService(int maxConnectionsPerService)
Sets the maximum number of connections that can be obtained to a particular
service, in a shared pool.
|
void |
setMaxPoolSize(int maxPoolSize)
Sets the maximum number of connections.
|
void |
setMinPoolSize(int minPoolSize)
Sets the minimum number of connections.
|
void |
setName(java.lang.String name)
Sets the name of the connection pool.
|
void |
setReadOnlyInstanceAllowed(boolean readOnlyInstanceAllowed)
Sets the read-only instance allowed value on the datasource.
|
void |
setSecondsToTrustIdleConnection(int secondsToTrustIdleConnection)
Sets the time in seconds to trust an idle connection to skip a validation
test.
|
void |
setShardingMode(boolean shardingMode)
This API changes the mode of UCP when UCP is using a Sharded Database.
|
void |
setTimeoutCheckInterval(int timeoutCheckInterval)
Sets the frequency (in seconds) to enforce the timeout properties.
|
void |
setTimeToLiveConnectionTimeout(int timeToLiveConnectionTimeout)
Sets the maximum time (in seconds) a connection may remain in-use.
|
void |
setValidateConnectionOnBorrow(boolean validateConnectionOnBorrow)
Makes the pool validate the connection before returning it to the user by
calling the JDBC API "isValid".
|
default void |
start()
if keepMetadataConn is not specified, assume it is "false".
|
void |
start(ConnectionRetrievalInfo connectionRetrievalInfo,
boolean keepMetadataConn)
Starts the connection pool.
|
void |
stop()
Stops the connection pool.
|
beginCurrentSql, debug, debug, endCurrentSql, format, getDiagnosable, isLoggingLevelFinest, resumeLogging, secure, suspendLogging, trace, traceUniversalPooledConnection borrowConnection(ConnectionRetrievalInfo connectionRetrievalInfo) throws UniversalConnectionPoolException
connectionRetrievalInfo - Info to use to get the connection.UniversalConnectionPoolException - if an error occurs getting a
connection.NoAvailableConnectionsException - if all of the connections are
in use.default java.util.concurrent.CompletionStage<UniversalPooledConnection> borrowConnectionAsync(ConnectionRetrievalInfo cri, java.util.concurrent.Executor executor) throws java.lang.UnsupportedOperationException
cri - Info to use to get the connection.executor - executor for asychronous processingjava.lang.UnsupportedOperationExceptionvoid returnConnection(UniversalPooledConnection pooledConnection) throws UniversalConnectionPoolException
pooledConnection - The connection to return back into the pool.UniversalConnectionPoolException - in case it is not possible to return connection.void closeConnection(UniversalPooledConnection pooledConnection) throws UniversalConnectionPoolException
pooledConnection - The pooled connection to close.UniversalConnectionPoolException - if an error occurs closing the
connection.void refresh()
throws UniversalConnectionPoolException
UniversalConnectionPoolException - in case it was not possible to refresh.void recycle()
throws UniversalConnectionPoolException
UniversalConnectionPoolException - in case it was not possible to recycle.void purge()
throws UniversalConnectionPoolException
refresh()
is that the connection pool is left empty with no connections available
after calling purge(). Some of the connection pool
properties such as minPoolSize or
initialPoolSize may not be honored when purging connections
from the pool.
Note that both borrowed and available connections are removed when this API is called. Any borrowed connections incur an exception after this API is called. The user is expected to retry and obtain a new connection from the pool.
UniversalConnectionPoolException - in case it was not possible to purge.void reconfigure(java.util.Properties props)
throws UniversalConnectionPoolException
props - Containing new set of pool properties for reconfiguration.UniversalConnectionPoolException - in case it wat not possible to reconfigure.void start(ConnectionRetrievalInfo connectionRetrievalInfo, boolean keepMetadataConn) throws UniversalConnectionPoolException
connectionRetrievalInfo - retrieval info with data for creation metadata connection.keepMetadataConn - keep metadata connection in the working set even if init pool size is 0
(because the next operation will be "borrow").UniversalConnectionPoolException - If an error occurs during
start.default void start()
throws UniversalConnectionPoolException
UniversalConnectionPoolExceptionvoid stop() throws UniversalConnectionPoolException
UniversalConnectionPoolException - in case it was not possible to stop.java.lang.String getName()
void setName(java.lang.String name)
name - The name of the connection pool.int getInitialPoolSize()
void setInitialPoolSize(int initialPoolSize)
throws UniversalConnectionPoolException
initialPoolSize - the initial pool size.UniversalConnectionPoolException - in case it was not
possible to set initial pool size.int getMinPoolSize()
void setMinPoolSize(int minPoolSize)
throws UniversalConnectionPoolException
minPoolSize - The minimum number of connections.UniversalConnectionPoolException - in case it was not
possible to set min pool size.int getMaxPoolSize()
void setMaxPoolSize(int maxPoolSize)
throws UniversalConnectionPoolException
maxPoolSize - The maximum number of connections.UniversalConnectionPoolException - in case it was not
possible to set max pool size.int getInactiveConnectionTimeout()
void setInactiveConnectionTimeout(int inactiveConnectionTimeout)
throws UniversalConnectionPoolException
inactiveConnectionTimeout - The inactive connection timeout
(in seconds).UniversalConnectionPoolException - in case it was not
possible to set timeout.int getAbandonedConnectionTimeout()
void setAbandonedConnectionTimeout(int abandonedConnectionTimeout)
throws UniversalConnectionPoolException
abandonedConnectionTimeout - The value of how long a connection
has not been used before it is
abandoned (in seconds).UniversalConnectionPoolException - in case it was not
possible to set timeout.@Deprecated int getConnectionWaitTimeout()
A borrow request may end up creating a new JDBC connection. Therefore, starting in 23.1, the value returned by this method may be larger than the configured one because UCP adjusts it so that it's always equal or larger than the CONNECT_TIMEOUT of the JDBC driver.
This method is deprecated.
Use getConnectionWaitDuration() instead.
setConnectionWaitTimeoutjava.time.Duration getConnectionWaitDuration()
Gets the maximum time (in java.time.Duration) that any connection borrow request can wait before it returns to the application.
A borrow request may end up creating a new JDBC connection. Therefore, starting in 23.1, the value returned by this method may be larger than the configured one because UCP adjusts it so that it's always equal or larger than the CONNECT_TIMEOUT of the JDBC driver.
setConnectionWaitDuration@Deprecated
void setConnectionWaitTimeout(int waitTimeout)
throws UniversalConnectionPoolException
Configures how much time a connection request call may wait before it either successfully returns a connection or throws an exception.
The wait timeou starts from the point when a connection borrow request is submitted to the pool.
During this time, UCP may either return a connection that's currently available in the pool (ideal scenario) or create a new connection if the pool hasn't reached its maximum size. Otherwise, UCP waits for a connection to be returned to the pool.
By default, the connection wait timeout is set to 3 seconds.
Setting the timeout to 0 makes UCP throw an exception immediately if there is no connection available and no room to grow the pool. Note that it still allows UCP to create a new connection if the maximum size hasn't been reached, and that may take some time.
This method is deprecated.
Use setConnectionWaitDuration(java.time.Duration) instead.
waitTimeout - The amount of time for a connection request to wait.UniversalConnectionPoolException - in case it was not
possible to set timeout.void setConnectionWaitDuration(java.time.Duration waitDuration)
throws UniversalConnectionPoolException
Configures how much time a connection request call may wait before it either successfully returns a connection or throws an exception.
The wait duration starts from the point when a connection borrow request is submitted to the pool.
During this time, UCP may either return a connection that's currently available in the pool (ideal scenario) or create a new connection if the pool hasn't reached its maximum size. Otherwise, UCP waits for a connection to be returned to the pool.
By default, the connection wait timeout is set to 3 seconds.
Setting the connection wait timeout to
Duration.ZERO makes UCP throw an exception immediately if there is no
connection available and no room to grow the pool. Note that it still allows UCP
to create a new connection if the maximum size hasn't been reached, and that may
take some time.
waitDuration - The duration for a connection request to wait.UniversalConnectionPoolException - in case it was not possible to set timeout.int getTimeToLiveConnectionTimeout()
void setTimeToLiveConnectionTimeout(int timeToLiveConnectionTimeout)
throws UniversalConnectionPoolException
timeToLiveConnectionTimeout - The maximum time (in seconds) a
used connection may be active.UniversalConnectionPoolException - in case it was not
possible to set timeout.int getTimeoutCheckInterval()
abandonedConnectionTimeout,
inactiveConnectionTimeout, and
timeToLiveConnectionTimeout.void setTimeoutCheckInterval(int timeoutCheckInterval)
throws UniversalConnectionPoolException
timeoutCheckInterval - The frequency (in seconds) to enforce
the timeout properties.UniversalConnectionPoolException - in case it was not
possible to set timeout.boolean getValidateConnectionOnBorrow()
true, connection validity
is performed before returning the connection to the user.void setValidateConnectionOnBorrow(boolean validateConnectionOnBorrow)
Makes the pool validate the connection before returning it to the user by calling the JDBC API "isValid".
Validating the connection each time it's borrowed from the pool has a performance cost because it typically requires a full roundtrip to the database. You can tune how the Oracle JDBC thin driver validates connections using the "oracle.jdbc.defaultConnectionValidation" property (please refer to the JDBC driver javadoc). You may also configure "secondsToTrustIdleConnection" to avoid validating connections that are often active.
validateConnectionOnBorrow - Whether or not a connection
being borrowed should first be
validated.setSecondsToTrustIdleConnectionint getConnectionHarvestTriggerCount()
void setConnectionHarvestTriggerCount(int connectionHarvestTriggerCount)
throws UniversalConnectionPoolException
connectionHarvestTriggerCount - The number of available
connections below which the
connection pool's connection
harvesting occurs.UniversalConnectionPoolException - in case it was not
possible to set count.int getConnectionHarvestMaxCount()
connectionHarvestMaxCount.void setConnectionHarvestMaxCount(int connectionHarvestMaxCount)
throws UniversalConnectionPoolException
connectionHarvestMaxCount - the maximum number of connections
that may be harvested when the
connection harvesting occurs.UniversalConnectionPoolException - in case it was not
possible to set timeout.int getAvailableConnectionsCount()
int getBorrowedConnectionsCount()
UniversalConnectionPoolStatistics getStatistics()
UniversalConnectionPoolLifeCycleState getLifeCycleState()
ConnectionRetrievalInfo getConnectionRetrievalInfo()
ConnectionRetrievalInfo object which contains
user and password information to create the connections.ConnectionRetrievalInfo object which contains user and
password information to create the connections.void setConnectionRetrievalInfo(ConnectionRetrievalInfo cri)
ConnectionRetrievalInfo for creating the initial
connections (physical connections) in the pool based on the
initialPoolSize property.cri - The ConnectionRetrievalInfo with user and
password for creating the initial connections in the pool.void registerConnectionAffinityCallback(ConnectionAffinityCallback cbk) throws UniversalConnectionPoolException
ConnectionAffinityCallback objet on the
connection pool.cbk - The affinity callback object to be registeredUniversalConnectionPoolException - If callback registration fails.void removeConnectionAffinityCallback()
throws UniversalConnectionPoolException
ConnectionAffinityCallback object registered on
the connection pool.UniversalConnectionPoolException - If callback removal fails.void registerConnectionLabelingCallback(ConnectionLabelingCallback cbk) throws UniversalConnectionPoolException
ConnectionLabelingCallback object with this
connection pool.cbk - The ConnectionLabelingCallback object to be
registered.UniversalConnectionPoolException - If there is a callback already
registered with this pool.void removeConnectionLabelingCallback()
throws UniversalConnectionPoolException
ConnectionLabelingCallback object registered
with this connection pool, if any.UniversalConnectionPoolException - If callback removal fails.long getMaxConnectionReuseTime()
setMaxConnectionReuseTime().void setMaxConnectionReuseTime(long maxConnectionReuseTime)
throws UniversalConnectionPoolException
maxConnectionReuseTime - Maximum connection reuse time (in seconds).UniversalConnectionPoolException - in case it was not
possible to set timeout.int getMaxConnectionReuseCount()
setMaxConnectionReuseCount().void setMaxConnectionReuseCount(int maxConnectionReuseCount)
throws UniversalConnectionPoolException
maxConnectionReuseCount - Maximum connection reuse count.UniversalConnectionPoolException - in case it was not
possible to set count.int getSecondsToTrustIdleConnection()
setSecondsToTrustIdleConnection().void setSecondsToTrustIdleConnection(int secondsToTrustIdleConnection)
throws UniversalConnectionPoolException
setValidateConnectionOnBorrow(boolean). When set to any
positive value, a connection validation during the checkout is skipped if
the connection was successfully used and returned to the pool within the
time specified for secondsToTrustIdleConnection.
Default value is set to 0 seconds which means that the feature is disabled.
With this mode enabled, UCP will do a SOCKET validation on every connection borrow and default driver validation type (can be changed with the "oracle.jdbc.defaultConnectionValidation" system property) after designated seconds to trust idle connection has passed
secondsToTrustIdleConnection - The value of how long a connection can be trusted to skip
connectionValidationOnBorrowUniversalConnectionPoolException - in case setter was failed.int getConnectionLabelingHighCost()
setConnectionLabelingHighCostvoid setConnectionLabelingHighCost(int highCost)
throws UniversalConnectionPoolException
cost(Properties, Properties)
method in ConnectionLabelingCallback to find a connection in the pool for a
request. When this property is set, connections with a cost value equal to
or greater than the property value are considered "high-cost" connections.
The default value is Integer.MAX_VALUE.highCost - The cost value that identifies a connection as "high-cost" for
connection labeling.UniversalConnectionPoolException - If an exception occurs while setting the cost.int getHighCostConnectionReuseThreshold()
setConnectionLabelingHighCost,
setHighCostConnectionReuseThresholdvoid setHighCostConnectionReuseThreshold(int threshold)
throws UniversalConnectionPoolException
threshold - The high-cost connection reuse threshold to set.UniversalConnectionPoolException - If any exception occurs while setting the threshold.int getMaxConnectionsPerService()
void setMaxConnectionsPerService(int maxConnectionsPerService)
throws UniversalConnectionPoolException
maxConnectionsPerService - The maximum number of connections that can be obtained to a
particular service.UniversalConnectionPoolException - If any exception occurs while setting the
maxConnectionsPerService value.int getConnectionRepurposeThreshold()
void setConnectionRepurposeThreshold(java.lang.Integer threshold)
throws UniversalConnectionPoolException
threshold - connection repurpose threshold to set.UniversalConnectionPoolException - If any exception occurs while setting the threshold.getConnectionRepurposeThresholdint getLoginTimeout()
void setLoginTimeout(int seconds)
throws UniversalConnectionPoolException
seconds - timeoutUniversalConnectionPoolException - in case of negative valueboolean isShareable()
void setShardingMode(boolean shardingMode)
shardingMode - Mode of UCP when using a Sharded Database.boolean getShardingMode()
void setConnectionValidationTimeout(int connectionValidationTimeout)
throws UniversalConnectionPoolException
connectionValidationTimeout - validation timeout in secondsUniversalConnectionPoolException - gets thrown in case of
negation timeout submittedint getConnectionValidationTimeout()
boolean isReadOnlyInstanceAllowed()
void setReadOnlyInstanceAllowed(boolean readOnlyInstanceAllowed)
readOnlyInstanceAllowed - whether to allow connection borrow to a read-only instance or not