You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2011/09/01 01:57:56 UTC

Re: svn commit: r1163864 - /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java

On 1 September 2011 00:10,  <ma...@apache.org> wrote:
> Author: markt
> Date: Wed Aug 31 23:10:53 2011
> New Revision: 1163864
>
> URL: http://svn.apache.org/viewvc?rev=1163864&view=rev
> Log:
> Stop multiple calls to close() triggering an JMX error
>
> Modified:
>    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
>
> Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
> URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1163864&r1=1163863&r2=1163864&view=diff
> ==============================================================================
> --- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original)
> +++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Wed Aug 31 23:10:53 2011
> @@ -1098,7 +1098,10 @@ public class GenericKeyedObjectPool<K,T>
>          evictionIterator = null;
>          evictionKeyIterator = null;
>          startEvictor(-1L);
> -         ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname);
> +         if (oname != null) {
> +             ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname);
> +             oname = null;
> +         }
>      }

If close() can be called from mulitple threads, then it's still
possible to unregister the bean twice.

I think the only way to fix this would be to synchronise the block -
making oname volatile would not help here.
Alternatively, use an atomic boolean to record the fact that the bean
has been registered.

>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1163864 - /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java

Posted by Mark Thomas <ma...@apache.org>.
On 01/09/2011 00:57, sebb wrote:
> On 1 September 2011 00:10,  <ma...@apache.org> wrote:
>> Author: markt
>> Date: Wed Aug 31 23:10:53 2011
>> New Revision: 1163864
>>
>> URL: http://svn.apache.org/viewvc?rev=1163864&view=rev
>> Log:
>> Stop multiple calls to close() triggering an JMX error
>>
>> Modified:
>>    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
>>
>> Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
>> URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1163864&r1=1163863&r2=1163864&view=diff
>> ==============================================================================
>> --- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original)
>> +++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Wed Aug 31 23:10:53 2011
>> @@ -1098,7 +1098,10 @@ public class GenericKeyedObjectPool<K,T>
>>          evictionIterator = null;
>>          evictionKeyIterator = null;
>>          startEvictor(-1L);
>> -         ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname);
>> +         if (oname != null) {
>> +             ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname);
>> +             oname = null;
>> +         }
>>      }
> 
> If close() can be called from mulitple threads, then it's still
> possible to unregister the bean twice.

Yep. This was more a quick fix to get past the unit test failures.

> I think the only way to fix this would be to synchronise the block -
> making oname volatile would not help here.
> Alternatively, use an atomic boolean to record the fact that the bean
> has been registered.

I'll take a look and see what is cleanest. I'd rather not introduce a
sync on the pool if I can help it.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org