Monica Shiralkar wrote:
Both concurrent HashMap and HashTable are used in a synchronized context. How to choose which one to use.
thanks
This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details
Mike. J. Thompson wrote:ConcurrentHashMap does not support nulls either.
Mike. J. Thompson wrote:To be honest I wasn't aware either until I read the Javadoc today. It throws a NullPointerException if either the key or value are null.
Thanks for the cow!
I hadn't been here for fifteen years
Jesper de Jong wrote:Class java.util.Hashtable is a legacy collection class, from before Java version 1.2. You shouldn't use it at all.
Just use a regular HashMap, and if you need synchronization, use ConcurrentHashMap. But do read about the thread safety of ConcurrentHashMap before you use it, so you understand what it means.
I hadn't been here for fifteen years
A.J. Côté wrote:
Jesper de Jong wrote:Class java.util.Hashtable is a legacy collection class, from before Java version 1.2. You shouldn't use it at all.
Just use a regular HashMap, and if you need synchronization, use ConcurrentHashMap. But do read about the thread safety of ConcurrentHashMap before you use it, so you understand what it means.
Jee, learn about synchronized statement first. We normally use specific Object to synchronize and monitor, not the instance nor the the class (static) monitor to handle things.
Usually, for best performance, we rather synchronize on our own defined monitors.
Nothing is magic.
Stephan van Hulst wrote:
A.J. Côté wrote:
Jee, learn about synchronized statement first. We normally use specific Object to synchronize and monitor, not the instance nor the the class (static) monitor to handle things.
Usually, for best performance, we rather synchronize on our own defined monitors.
Gee. Learn about the concurrency API first. Synchronized is old hat. Use locks and conditions.
A.J. Côté wrote:
Jee, learn about synchronized statement first. We normally use specific Object to synchronize and monitor, not the instance nor the the class (static) monitor to handle things.
Usually, for best performance, we rather synchronize on our own defined monitors.
Nothing is magic.