[concurrency-interest] Question about Double-checked locking

Tutika Chakravarthy chakritsus at yahoo.com
Sun May 14 05:17:26 EDT 2006


Hi All,
I have some code like this : 

result = map.get(key);


if (result == null ) {

Object mutex = mutexFactory.getMutex(key);

synchronized (mutex) {
result = map.get(key);

if (result == null) {
	result = dataSource.load(key);

	if (result != null) 
	map.put(key, result);
	else
	mutexFactory.removeMutex(key);

	}
 }
}

Here mutexFactory returns different monitors based on
the key . 
I am using HashMap to store and retrieve the values . 
If the value is not there in the map , I should load
the value from DataBase using dataSource.

I would like to know whether the above code falls
under "Double-checked locking" problem.


If so , Can I avoid it using new util.concurrent.Lock
interface classes ?

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Concurrency-interest mailing list