[
https://issues.apache.org/jira/browse/POOL-299?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Phil Steitz updated POOL-299:
-----------------------------
Fix Version/s: 3.0
> testOnBorrow overrides testOnCreate=false, add testOnReuse to complement
> testOnCreate
> -------------------------------------------------------------------------------------
>
> Key: POOL-299
> URL: https://issues.apache.org/jira/browse/POOL-299
> Project: Commons Pool
> Issue Type: Improvement
> Affects Versions: 2.4
> Environment: DBCP 2.1.0 with Commons Pool 2.4.0
> Reporter: Justin Cranford
> Priority: Minor
> Labels: performance
> Fix For: 3.0
>
>
> I am using Commons DBCP 2.1 with Commons Pool 2.4. When borrowing a
> connection from DBCP, the underlying pool either reuses a connection or
> creates a new connection. Validation of that connection seems to be triggered
> in borrowObject() of GenericKeyedObjectPool or GenericObjectPool based on two
> settings passed from DBCP 2.1.
> if (p != null && (getTestOnBorrow() || create && getTestOnCreate())) {
> I would like to only validate reused connections, not new connections.
> Validating a new connection is redundant since successful creation of a
> connection implies it is already valid. Commons Pools 2 does not allow me to
> only validate reused connections, though. If I set testOnBorrow=true, then
> Commons Pool 2 validates new or reused connections, and testOnCreate is
> effectively overridden. If I set testOnBorrow=false, then my only option to
> set testOnCreate=true, but that does not match what I need either. No
> combination of these two parameters will work the way I want.
> I would like to offer a possible solution. If Commons Pool 2 were to add a
> new setting called testOnReuse, it would compliment testOnCreate like so:
> > if (p != null && ((getTestOnBorrow()) || (!create &&
> > getTestOnReuse()) || (create && getTestOnCreate()))) {
> This solution allows testOnBorrow to be backwards compatible - it validates
> both new or reused objects, and it overrides testOnCreate (and testOnReuse).
> However, now I have the option to only validate reused connections, not new
> connections, with this combination of settings:
> - testOnBorrow=false
> - testOnCreate=false
> - testOnReuse=true
> In short, adding testOnReuse would fix the current inability to only validate
> reused objects. It would have the same default value as testOnCreate. If it
> can be added to Commons Pool 2, then I would open an enhancement ticket for
> Commons DBCP 2 to expose it in its programmatic API and config. Any other
> project depending on Commons Pool 2 would benefit as well.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)