commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Speakmon (JIRA)" <>
Subject [jira] Commented: (POOL-91) StackObjectPool.borrowObject infinate loop when makeObject returns null
Date Fri, 08 Dec 2006 20:32:23 GMT
    [ ] 
Ben Speakmon commented on POOL-91:

I'm not sure I like throwing the exception either. I can think of situations where I might
want borrowings to fail silently or even have the borrower create its own instance of the
object if it can't get one from the pool.

This is admittedly a major change, but I think it would be neat to take exceptions out of
the borrowObject() signature and allow users to specify a handler for when borrow() fails.
Imagine an interface like:

public interface FailedBorrowHandler() {
    void failedBorrow(ObjectPool pool);

and a method in ObjectPool:

void setFailedBorrowHandler(FailedBorrowHandler handler);

Clients can then implement this interface to do whatever they want when a borrow fails. Maybe
the objects in the pool aren't expected to be readily available and so borrowObject() is expected
to fail half the time; in that case, requiring the caller to handle a checked exception is
a pain, not a gain. If you're pooling threads, you may want to wait a few seconds and then
try to borrow again, or even kill a currently engaged low-priority thread and replace it with
your high-priority task.

As I said, this is a huge change, but after having used this approach in JDK 1.5's java.util.concurrent.ThreadPoolExecutor,
I've become a big fan of handling pools like this.

> StackObjectPool.borrowObject infinate loop when makeObject returns null
> -----------------------------------------------------------------------
>                 Key: POOL-91
>                 URL:
>             Project: Commons Pool
>          Issue Type: Bug
>            Reporter: Sandy McArthur
>         Assigned To: Sandy McArthur
> StackObjectPool.borrowObject has a infinate loop when makeObject returns null.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message