You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Calvin Yu <ca...@mindspring.com> on 2001/07/02 14:15:19 UTC
Re: Fast Hashmap doubt .
If you look at FashHashMap.get(Object key), you'll notice that the call
to map.get() is not synchronized. If FashHashMap.put() isn't
implemented like this, you'll run into a race condition when one thread
calls map.put() and another calls map.get().
Calvin
----- Original Message -----
From: suhas <ma...@techmas.hcltech.com>
To: struts-user@jakarta.apache.org
<ma...@jakarta.apache.org>
Sent: Saturday, July 01, 2000 5:47 AM
Subject: Fast Hashmap doubt .
I was going through put ( ) and putAll ( ) methods in Fast HashMap code
in the struts . But did not get why we need to clone the HashMap and add
a entry to that cloned map then move that cloned map to original HashMap
. In multi- threaded enviornment anyway we synchronized the code that
accesses the HashMap in the put method .. ?
public Object put(Object key, Object value) {
if (fast) {
synchronized (this) {
// IF U synchronize the code like this then easily only one thread can
manipulate the HashMap
HashMap temp = (HashMap) map.clone(); // What
this do then ?
Object result = temp.put(key, value); //
map = temp;
//
return (result);
}
} else {
synchronized (map) {
return (map.put(key, value));
}
}
}