commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Valentin Mayamsin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (POOL-283) 'Object has already been retured to this pool or is invalid' for collections
Date Thu, 05 Feb 2015 17:50:35 GMT

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

Valentin Mayamsin commented on POOL-283:
----------------------------------------

I resolved this issue in my project by switching to 1.6, it doesn't have this issue since
it's implemented differently. For 2.x let me suggest wrapping objects into a wrapper similar
this (pseudo-code):

{code}
class IdentityWrapper {
    Object obj;
    IdentityWrapper(Object obj) {
        this.obj=obj;
    }
    boolean equals(Object that) {
         return that==obj;
    }
    int hashCode() {
        return System.identityHashcode(obj);
    }
}
{code}

The drawback is it will create extra object for each returnObject(Object obj) call. I'm not
sure how significant is it.

> 'Object has already been retured to this pool or is invalid' for collections
> ----------------------------------------------------------------------------
>
>                 Key: POOL-283
>                 URL: https://issues.apache.org/jira/browse/POOL-283
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Valentin Mayamsin
>
> This test throws exception:
> {code}
>  GenericObjectPoolConfig config = new GenericObjectPoolConfig ();
>         config.setMaxTotal ( 2 );
>         GenericObjectPool<Set> setsPool = new GenericObjectPool<> ( new BasePooledObjectFactory<Set>
()
>         {
>             @Override
>             public Set create () throws Exception
>             {
>                 return new HashSet();
>             }
>             @Override
>             public PooledObject<Set> wrap ( Set o )
>             {
>                 return new DefaultPooledObject<> ( o );
>             }
>             @Override
>             public void passivateObject ( PooledObject<Set> p ) throws Exception
>             {
>                 p.getObject ().clear ();
>                 super.passivateObject ( p );
>             }
>         }, config );
>         final Set set1 = setsPool.borrowObject ();
>         final Set set2 = setsPool.borrowObject ();
>         setsPool.returnObject ( set1 );
>         setsPool.returnObject ( set2 ); // this throws java.lang.IllegalStateException:
Object has already been retured to this pool or is invalid
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message