You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by movie user <mo...@gmail.com> on 2009/01/13 23:37:02 UTC
Is invalidateObject() necessary is makeObject() throws exception
Hello Everyone,
I have a question on the common pool.
I have a makeObject() method inside the factory class. Now if this method
throws any exception do I need to do pool.invalidateObject() in the catch
block.
e.g
try {
pool.borrowObject()l
}
catch (Exception e) {
pool.invalidateObject();
}
Factory class
public Object makeObject() throws Exception {
try {
} catch (Exception e) {
throw e;
}
return <some object>
}
Re: Is invalidateObject() necessary is makeObject() throws exception
Posted by Martin Thelian <Ma...@gmx.at>.
Hi!
movie user schrieb:
> I have a makeObject() method inside the factory class. Now if this method
> throws any exception do I need to do pool.invalidateObject() in the catch
> block.
>
If an exceptions is thrown during pooled-object creation, the exception
will be propagated to the code requesting the object. So you have
nothing to invalidate in your code.
If you have the following code
|> Object obj = null;
|> try {
|> obj = pool.borrowObject();
|> [...]
|> } catch(Exception e) {
|> if (obj != null) pool.invalidateObject(obj);
|> }
then obj is null in this situation.
Regards,
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Is invalidateObject() necessary is makeObject() throws exception
Posted by Phil Steitz <ph...@gmail.com>.
movie user wrote:
> Hello Everyone,
>
> I have a question on the common pool.
>
> I have a makeObject() method inside the factory class. Now if this method
> throws any exception do I need to do pool.invalidateObject() in the catch
> block.
>
If I understand your question correctly, the answer is no. If your
factory's makeObject throws an exception, the pool method (borrow or
add) that invokes the factory method will not catch the exception and no
object will be added to the pool, so there is nothing to invalidate.
Phil
> e.g
>
> try {
> pool.borrowObject()l
> }
> catch (Exception e) {
> pool.invalidateObject();
> }
>
> Factory class
>
> public Object makeObject() throws Exception {
> try {
>
> } catch (Exception e) {
> throw e;
> }
> return <some object>
>
> }
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org