commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jochen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (POOL-102) Thread waiting forever for borrowObject() cannot be interrupted
Date Fri, 18 Jul 2008 03:52:31 GMT

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

jochen commented on POOL-102:
-----------------------------

Steitz,

It seems the Revision #549729 doesn't work. we met the issue on the HTTP threads being response
to concurrent 40 users, which made the connection pool was exhausted and all of HTTP threads
waiting on GenericObjectPool.borrowObject happened.

Given the commons pool v2.0 doesn't come out, I got the v1.4 and was pleased to see the bug
fixes list  -  Allowed blocked threads in GenericObjectPool borrowObject to be interrupted.
Issue: POOL-102.  But unfortunately it didn't fix our issue when I replaced the v1.4 with
v1.3.  HTTP threads were still waiting for GenericObjectPool.borrowObject.

is it any solution to solve it out or any workaround exists? many thanks.

> Thread waiting forever for borrowObject() cannot be interrupted
> ---------------------------------------------------------------
>
>                 Key: POOL-102
>                 URL: https://issues.apache.org/jira/browse/POOL-102
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 1.1, 1.2, 1.3
>            Reporter: John Sumsion
>            Priority: Minor
>             Fix For: 2.0
>
>
> In the following GenericObjectPool snippet inside borrowObject(), InterruptedException
is caught and ignored.
>                             case WHEN_EXHAUSTED_BLOCK:
>                                     try {
>                                         if(_maxWait <= 0) {
>                                             wait();
>                                         } else {
>                                             wait(_maxWait);
>                                         }
>                                     } catch(InterruptedException e) {
>                                         // ignored
>                                     }
> There are two problems here:
> 1) a thread waiting forever to get an object out of the pool will NEVER terminate, even
if interrupted
> 2) even if you put a "throw e" in, it will still be wrong because the thread's interrupted
status is not preserved
> This will cause cancellation problems for threads that are inside borrowObject() that
want to terminate early ONLY if they are interrupted.
> For example, if a borrow-and-wait-forever was running on an pooled executor thread in
Java 1.5 and the executor service tried to cancel a task and that task had early-termination
logic in it that checked interrupted status to terminate early, the task would never be cancelled.
> For us, this is minor because we are on a Tomcat request thread that has to wait for
this resource to continue, but for others that have pools of stuff that are being used by
time-bound tasks, it's inconvenient to write code that waits for what ends up being arbitrary
time periods for a wait.  It would be easier to just say wait forever and allow interruption
by someone else who is watching me.
> Suggestion: make the code read like this:
>                             case WHEN_EXHAUSTED_BLOCK:
>                                     try {
>                                         if(_maxWait <= 0) {
>                                             wait();
>                                         } else {
>                                             wait(_maxWait);
>                                         }
>                                     } catch(InterruptedException e) {
>                                         Thread.currentThread().interrupt();
>                                         throw e;
>                                     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message