[ 
https://issues.apache.org/jira/browse/POOL-418?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17902153#comment-17902153
 ] 

SunShuai commented on POOL-418:
-------------------------------

hello [~ggregory] 

When there are no available objects in the connection pool, the current thread 
enters the {{create}} method to [create a connection 
|https://github.com/apache/commons-pool/blob/1c0095548ff8810f8ef6a9dabebfd57cf1a1b9b2/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java#L300]

If the maximum number of connections has already been reached and other threads 
are creating connections, [the current thread will wait for a duration 
specified by {{maxWaitMillis }}| 
https://github.com/apache/commons-pool/blob/1c0095548ff8810f8ef6a9dabebfd57cf1a1b9b2/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java#L537].
 If the wait ends and the maximum connection limit is still reached, the 
{{create}} method [will return 
{{{}null{}}}|[https://github.com/apache/commons-pool/blob/1c0095548ff8810f8ef6a9dabebfd57cf1a1b9b2/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java#L553].]
 

 

If {{blockWhenExhausted}} is enabled, [the current thread will block and wait 
in the 
queue|https://github.com/apache/commons-pool/blob/1c0095548ff8810f8ef6a9dabebfd57cf1a1b9b2/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java#L307],
 with the wait time also determined by {{{}maxWaitMillis{}}}. 

Looking at the entire process, the total wait time will be {{{}createWait + 
pollFirstWait = 2 * maxWaitMillis{}}}.

Do you think it’s necessary to calculate the remaining wait time during the 
second wait?

> The maximum wait time for GenericObjectPool.borrowObject(*) may exceed 
> expectations due to a spurious thread wakeup
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: POOL-418
>                 URL: https://issues.apache.org/jira/browse/POOL-418
>             Project: Commons Pool
>          Issue Type: Bug
>            Reporter: SunShuai
>            Assignee: Gary D. Gregory
>            Priority: Minor
>             Fix For: 2.12.1
>
>         Attachments: 74C00A2F-EE3A-4660-BE58-66CA37F9808A.png, 
> EE4BD798-26B6-4AE1-B114-5AC7342B31A6.png
>
>
> I found an issue when using jedis to operate Redis database, Here is the 
> issue link -> [https://github.com/redis/jedis/issues/4014]. we feel that it's 
> a problem with the Commons pool.
>  
> In situations where the connection is tight, the waiting time can be up to 
> twice the maxWaitMillis consumption.
> code: org.apache.commons.pool2.impl.GenericObjectPool#borrowObject(long) -> 
> org.apache.commons.pool2.impl.GenericObjectPool#create
> The thread that failed to create the connection will wake up the thread that 
> is waiting to be created. Threads that do not compete for resources will wait 
> again, and the waiting time will still be the maxWaitMillis.
> If the first waiting time is ( maxWaitMillis - 1ms), plus the second full 
> waiting time, then the full waiting time will be twice the expected time.
>  
> The waiting time we hope for this time is the total waiting time minus the 
> time already waited.
>  
> such as: Duration remainingWait = 
> localMaxWaitDuration.minus(Duration.between(localStartInstant, 
> Instant.now()));
> if (remainingWait.isNegative()) {
> create = Boolean.FALSE;
> } else {
> wait(makeObjectCountLock, remainingWait);
> }
>  
> We are not sure if this issue has been addressed and look forward to your 
> reply.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to