The docs say that Hashtable is synchronized. Does that mean that I
don't have to prevent concurrent gets/puts with my own synchronization?
I'm not concerned about manipulating the Iterators just storing and
retrieving elements.
Thanks,

Signature
Knute Johnson
email s/nospam/knute/
Yes, Hashtable is sync.
--
garskof
> The docs say that Hashtable is synchronized. Does that mean that I
> don't have to prevent concurrent gets/puts with my own synchronization?
> I'm not concerned about manipulating the Iterators just storing and
> retrieving elements.
Each get and put will be correctly synchronised.
However, sequences of operations will not be. Consider:
Value value = table.get(key);
if (value == null) {
value = new Value();
table.put(key, value);
}
Between the get and put another thread may have inserted an entry under
the same key. So either synchronise the whole block against the
Hashtable, or from 1.5 use a ConcurrentMap and replace put with putIfAbsent.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Knute Johnson - 08 Feb 2006 03:43 GMT
>> The docs say that Hashtable is synchronized. Does that mean that I
>> don't have to prevent concurrent gets/puts with my own
[quoted text clipped - 17 lines]
>
> Tom Hawtin
Thanks Tom.

Signature
Knute Johnson
email s/nospam/knute/
> The docs say that Hashtable is synchronized. Does that mean that I don't
> have to prevent concurrent gets/puts with my own synchronization?
Yes, exactly.
Looking into the source of Hashtable, you see that all its data-accessing
methods (get, put, isEmpty, size, clear, remove, ......) are synchronized by
themselves. So there is no need for you to guard them with your own sync.
> I'm not concerned about manipulating the Iterators just storing and
> retrieving elements.

Signature
"TFritsch$t-online:de".replace(':','.').replace('$','@')
Knute Johnson - 08 Feb 2006 03:44 GMT
>> The docs say that Hashtable is synchronized. Does that mean that I don't
>> have to prevent concurrent gets/puts with my own synchronization?
[quoted text clipped - 5 lines]
>> I'm not concerned about manipulating the Iterators just storing and
>> retrieving elements.
Thanks Tom.

Signature
Knute Johnson
email s/nospam/knute/