I
Ian Pilcher
I've got a map that will be access by multiple threads, so I'm
considering using Collections.synchronizedMap to "wrap" it. There will
be occasions, though, where I will need to manually synchronize.
synchronized (syncMap)
{
if (syncMap.containsKey(key))
throw new AlreadyGotOneException();
syncMap.put(key, value);
}
This "double synchronization" seems inelegant, and possibly wasteful.
Is there a consensus on the best practice in this situation?
Thanks!
considering using Collections.synchronizedMap to "wrap" it. There will
be occasions, though, where I will need to manually synchronize.
synchronized (syncMap)
{
if (syncMap.containsKey(key))
throw new AlreadyGotOneException();
syncMap.put(key, value);
}
This "double synchronization" seems inelegant, and possibly wasteful.
Is there a consensus on the best practice in this situation?
Thanks!