[concurrency-interest] ConcurrentHashmap.putIfAbsent oddities

Gregg Wonderly gregg at cytetech.com
Fri Dec 8 16:39:45 EST 2006


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@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@7fc8b2,LoaderKey: 
(parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@56c3cf, 
LoaderKey: (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@515263, 
LoaderKey: (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@515263, 
LoaderKey: (parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@515263,LoaderKey: 
(parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@515263,LoaderKey: 
(parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@515263,LoaderKey: 
(parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@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@515263,LoaderKey: 
(parentnull=false) [vhttp://eoi1.cytetech.com:8090/reggie-dl.jar, 
vhttp://eoi1.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@7fc8b2, 
LoaderKey: (parentnull=false) [vhttp://mdp4.cytetech.com:8090/reggie-dl.jar, 
vhttp://mdp4.cytetech.com:8090/jsk-dl.jar]=java.util.concurrent.FutureTask@f81402}


More information about the Concurrency-interest mailing list