D
David
I'd like to have a collection where access to the elements is synchronized.
Looking at the API, it seems that many collections aren't synchronized by
default but that it is possible to obtain a synchronized collection by
calling, for example, Collections.synchronizedSet(Set s).
Are there any disadvantages to doing the above? Is the returned set fully
thread-safe - eg. are the add and remove methods synchronized? Is there a
better alternative?
The reason I ask is that it seems a common requirement to have synchronized
collections and I'm surprised you have to rely on a static method within the
Collections Class.
Thanks for any advice,
David
Looking at the API, it seems that many collections aren't synchronized by
default but that it is possible to obtain a synchronized collection by
calling, for example, Collections.synchronizedSet(Set s).
Are there any disadvantages to doing the above? Is the returned set fully
thread-safe - eg. are the add and remove methods synchronized? Is there a
better alternative?
The reason I ask is that it seems a common requirement to have synchronized
collections and I'm surprised you have to rely on a static method within the
Collections Class.
Thanks for any advice,
David