[concurrency-interest] ConcurrentHashmap.putIfAbsent oddities

Tim Peierls tim at peierls.net
Fri Dec 8 16:50:13 EST 2006


map.putIfAbsent uses identity semantics and map.get uses equals/hashCode
semantics.

--tim

On 12/8/06, Gregg Wonderly <gregg at cytetech.com> wrote:
>
> I recently made some changes to a single large synchronized() block to use
> Futures and ConcurrentHashmap to distribute the locking to a finer grain.
>
> I've been seeing some oddities in the behavior of the code after these
> changes,
> and today, I took a deeper look.  There is quite a bit of context and
> complexity
> around this code, it involves classloader creation in an RMIClassLoaderSPI
> implementation.  But, the basics are that when I use
>
>         LoaderKey key = ...
>         Future fut = ...
>         Future runfut = map.putIfAbsent( key, fut );
>         logger.info(this+": loader key[cur="+runfut+"] for access is:
> \""+key+"\",
> know: "+map );
>
> I see that method returning null for multiple calls with the same key (as
> shown
> in the logging below).  If I change that single call to be
>
>         LoaderKey key = ...
>         Future fut = ...
>         Future runfut = null;
>         synchronized( map ) {
>                 runfut = map.get( key );
>                 if( runfut == null )
>                         map.put( key, fut );
>         }
>
> I see the expected behavior.
>
> map is a class level object.  There is only a single instance of this
> class
> active and thus only one map defined.
>
> Any thoughts on what I might be overlooking?
>
> Gregg Wonderly
>
> -------------------------------------------------------------------------
> 12/08/2006 15:33:29 [net.jini.loader.pref.PreferredClassProvider#10] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader key[cur=null]
> for
> access is: "LoaderKey: (parentnull=false)
> [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 15151aa}
>
> 12/08/2006 15:33:29 [net.jini.loader.pref.PreferredClassProvider#11] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader key[cur=null]
> for
> access is: "LoaderKey: (parentnull=false)
> [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 15151aa}
>
> 12/08/2006 15:33:29 [net.jini.loader.pref.PreferredClassProvider#12] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader
> key[cur=java.util.concurrent.FutureTask at 7fc8b2] for access is: "LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,LoaderKey:
> (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 15151aa}
>
> 12/08/2006 15:33:29 [net.jini.loader.pref.PreferredClassProvider#13] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader key[cur=null]
> for
> access is: "LoaderKey: (parentnull=false)
> [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 56c3cf,
> LoaderKey: (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 15151aa}
>
> 12/08/2006 15:33:29 [net.jini.loader.pref.PreferredClassProvider#14] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader key[cur=null]
> for
> access is: "LoaderKey: (parentnull=false)
> [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 515263,
> LoaderKey: (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at f81402}
>
> 12/08/2006 15:33:29 [net.jini.loader.pref.PreferredClassProvider#15] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader key[cur=null]
> for
> access is: "LoaderKey: (parentnull=false)
> [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 515263,
> LoaderKey: (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at f81402}
>
> 12/08/2006 15:33:30 [net.jini.loader.pref.PreferredClassProvider#16] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader
> key[cur=java.util.concurrent.FutureTask at 7fc8b2] for access is: "LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 515263,LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at f81402}
>
> 12/08/2006 15:33:30 [net.jini.loader.pref.PreferredClassProvider#17] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader
> key[cur=java.util.concurrent.FutureTask at 7fc8b2] for access is: "LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 515263,LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at f81402}
>
> 12/08/2006 15:33:30 [net.jini.loader.pref.PreferredClassProvider#18] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader
> key[cur=java.util.concurrent.FutureTask at 515263] for access is: "LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 515263,LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at f81402}
>
> 12/08/2006 15:33:30 [net.jini.loader.pref.PreferredClassProvider#19] INFO
> #
> net.jini.loader.pref.PreferredClassProvider at 2a5ab9: loader
> key[cur=java.util.concurrent.FutureTask at f81402] for access is: "LoaderKey:
> (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]", know: {LoaderKey:
> (parentnull=false) [vhttp://mdp3.cytetech.com:8090/reggie-dl.jar,
> vhttp://mdp3.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 515263,LoaderKey:
> (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar,
> vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at 7fc8b2,
> LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-
> dl.jar,
> vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=
> java.util.concurrent.FutureTask at f81402}
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20061208/7f1c1d4f/attachment-0001.html 


More information about the Concurrency-interest mailing list