commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <>
Subject Re: correct behavior for object pooling ??- > maybe BUG ??
Date Tue, 21 Oct 2003 21:08:54 GMT
It is correct that the pool doesn't block returning the same object 
twice. If you do that by accident bad things will happen.

Therefor it is recommended to keep an "active" flag on the object 
itself. This has the additional advantage that you can use the same flag 
to block other methods when the object is in the pool (not active).
See dbcp for an example:

This check isn't done in the pool code for performance reasons.
But improvements are always welcome ;-)

Does this answer your question?

-- Dirk

Eddie Post wrote:

> Hellu,
> I am using Commons Pool and detecting some strange behavior when 
> returning the same object two times (in some junit tests). What should 
> be the correct behavior ?
> I now signal that:
> - The first returnObject returns the object to the pool and makes it idle
> - The second returnObject removes the object, so it's not idle anymore.
> - When I then retrieve two new objects without returning any of them, I 
> notice that they are the same :(. I don't think this is the corect 
> behavior, as when the code contains some bug and the same object is 
> returned two times, the other pool code will also fail.. or not ??
> Why is this ?
> What I have ?:
> I have a GenericKeyedObjectPool and a KeyedPoolableObjectFactory. In the 
> factory I only implemented the makeObject method. I pass a Class as 
> argument such that I can use only one makeObject method to create 
> different kind of object instances.
> Please some help on how to solve this ?
> Regards,
> Ed Bras

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

View raw message