You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2025/06/06 01:24:00 UTC
[jira] [Commented] (POOL-422) GenericObjectPool.create
[ https://issues.apache.org/jira/browse/POOL-422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17956478#comment-17956478 ]
Gary D. Gregory commented on POOL-422:
--------------------------------------
[~shengulong]
I'm not exactly sure what you are trying to say but it would be clearer if you created a pull request on GitHub with a.unit test.
> GenericObjectPool.create
> ------------------------
>
> Key: POOL-422
> URL: https://issues.apache.org/jira/browse/POOL-422
> Project: Commons Pool
> Issue Type: Improvement
> Affects Versions: 2.12.1
> Reporter: shengulong
> Priority: Major
>
> private PooledObject<T> create(final Duration maxWaitDuration) throws Exception {
> final Instant startInstant = Instant.now();
>
> Duration remainingWaitDuration =
> maxWaitDuration.isNegative() ? Duration.ZERO : maxWaitDuration;
>
> int localMaxTotal = getMaxTotal();
> // This simplifies the code later in this method
> if (localMaxTotal < 0)
> { localMaxTotal = Integer.MAX_VALUE; }
>
> final Instant localStartInstant = Instant.now();
> // Flag that indicates if create should:
> // - TRUE: call the factory to create an object
> // - FALSE: return null
> // - null: loop and re-test the condition that determines whether to
> // call the factory
> Boolean create = null;
>
> while (create == null) \{ // remainingWaitDuration handles spurious wakeup from wait(). remainingWaitDuration = remainingWaitDuration.minus(durationSince(startInstant)); ... }
> ...
> }
>
> should be:
>
> private PooledObject<T> create(final Duration maxWaitDuration) throws Exception {
> final Instant startInstant = Instant.now();
>
> Duration maxWaitDuration =
> maxWaitDuration.isNegative() ? Duration.ZERO : maxWaitDuration;
>
> int localMaxTotal = getMaxTotal();
> // This simplifies the code later in this method
> if (localMaxTotal < 0) \{ localMaxTotal = Integer.MAX_VALUE; }
>
> final Instant localStartInstant = Instant.now();
> // Flag that indicates if create should:
> // - TRUE: call the factory to create an object
> // - FALSE: return null
> // - null: loop and re-test the condition that determines whether to
> // call the factory
> Boolean create = null;
>
> while (create == null)
> { // remainingWaitDuration handles spurious wakeup from wait(). remainingWaitDuration = maxWaitDuration.minus(durationSince(startInstant)); ... }
> ...
> }
--
This message was sent by Atlassian Jira
(v8.20.10#820010)