Three ways to make HashMap thread-safe

  • Use: Hashtable which is thread-safe;
  • Use: Hashmap objHashmap = Collections.synchronizedMap(new HashMap(….));
  • Use: Block Synchronization mechanism. Where ever you are using the HashMap put those codes into block and sysnchronise that block with respect to HashMap object that you are having.

~ by yingliang on July 7, 2009.

Leave a Reply




*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image