how to make hashmap threadsafe
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   pravin_sahu
Posted On:   Monday, March 6, 2006 01:55 AM

i want to make hashmap as threadsafe, how?

Re: how to make hashmap threadsafe

Posted By:   rahul123  
Posted On:   Wednesday, December 18, 2013 09:27 PM

Map map = new Collections.synchronizedMap(new HashMap());

for createing threadsafe hashmap

Re: how to make hashmap threadsafe

Posted By:   Amit_Saxena  
Posted On:   Wednesday, April 26, 2006 03:48 AM

Use :
Hashmap objHashmap = Collections.synchronizedMap(new HashMap(....));

Re: how to make hashmap threadsafe

Posted By:   ankush_purwar  
Posted On:   Monday, March 6, 2006 01:46 PM

Why not you prefer Hashtable because it's thread-safe ?
otherwise you can make a wrapper class around the hashmap and provide same API's as provided by HashMap and make the relevant API as synchronized.

Re: how to make hashmap threadsafe

Posted By:   WarnerJan_Veldhuis  
Posted On:   Monday, March 6, 2006 04:17 AM

Map myThreadSafeMap = Collections.synchronizedMap( new HashMap() );

See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#synchronizedMap(java.util.Map)

Re: how to make hashmap threadsafe

Posted By:   rajeev_ranjan  
Posted On:   Monday, March 6, 2006 04:08 AM

Hi pravin


why don't you try 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.

About | Sitemap | Contact