commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (POOL-284) "Returned object not currently part of this pool" when using mutable objects
Date Mon, 09 Mar 2015 13:06:38 GMT

     [ https://issues.apache.org/jira/browse/POOL-284?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Phil Steitz updated POOL-284:
-----------------------------
    Attachment: identityWrapper.patch

Here is another patch to consider, implementing wrapping.  Note that there is no "unwrapping"
required - we just need to wrap instances when creating hash keys. 

I have been able to measure a 5-7% decrease in throughput when using StaticBucketMap, but
no consistent decrease with this patch.  I don't have a machine with a lot of cores to test
with though.  Anyone with interest and available cores can use the primitive JMH setup I have
[here | https://github.com/psteitz/pool-test]

> "Returned object not currently part of this pool" when using mutable objects
> ----------------------------------------------------------------------------
>
>                 Key: POOL-284
>                 URL: https://issues.apache.org/jira/browse/POOL-284
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Valentin Mayamsin
>         Attachments: StaticBucketMap-mods.patch, identityWrapper.patch, pool-283-4.patch
>
>
> I'm using pool to reuse expensive Sets (storing millions of items). Here is a test which
fails:
> {code}
>         GenericObjectPoolConfig config = new GenericObjectPoolConfig ();
>         GenericObjectPool<Set> aPool = 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 );
>         Set set = aPool.borrowObject ();
>         set.add ( new Object () );
>         
>         aPool.returnObject ( set );
> {code}
> This is because GenericObjectPool uses a HashMap<Object, PooledObject> to correlate
objects and state. HashMap stores objects correlated to their hashCode. So in case object's
state change then hashCode will change, thus Map will fail to correlate this object since
it stores old hashCode



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

Mime
View raw message