commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (POOL-284) "Returned object not currently part of this pool" when using mutable objects
Date Mon, 23 Feb 2015 08:32:12 GMT

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

Thomas Neidhart commented on POOL-284:
--------------------------------------

When using the StaticBucketMap, we need to ensure that the number of elements in the pool
does not exceed the number of buckets as otherwise the performance will degrade.
Fortunately, a pool is limited in size, so we can use the getMaxTotal() to initialize the
map, but it would also mean that we need to re-create the map when using the setter.

To make the behavior configurable, we could also do the following:

 * take the Equator interface from collections
 * change the StaticBucketMap to use an Equator when calling hashCode / equals for an element
 * depending on the setting, we use an IdentityEquator (uses System.identityHashCode and reference
equality) or an DefaultEquator (delegates to the object's hashCode / equals methods)

> "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, 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