How to Synchronize the HashMap

Any Body Tell about this

Questions by kg.shankar   answers by kg.shankar

Showing Answers 1 - 15 of 15 Answers

gpp

  • Oct 19th, 2005
 

Collections.getSynchronizedMap(HashMap)

  Was this answer useful?  Yes

Venkateswarlu

  • Oct 20th, 2005
 

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

  Was this answer useful?  Yes

Yogesh Kumar

  • Oct 21st, 2005
 

java.util.Collectios.synchronizedMap(Map w)

this returns synchronized map.

  Was this answer useful?  Yes

ramanan

  • Oct 21st, 2005
 

Hi ,the solution is Map m=Collections.synchronizedMap(new HashMap(..))---ramanan--

  Was this answer useful?  Yes

Suresh Raju Ch

  • Oct 22nd, 2005
 

We can synchronize HashMap using Collections.synchronizeMap()

  Was this answer useful?  Yes

sridhar

  • Nov 3rd, 2005
 

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

  Was this answer useful?  Yes

sekhar

  • Nov 10th, 2005
 

collection.synchronize(map)

  Was this answer useful?  Yes

sukumar Reddy

  • Nov 18th, 2005
 

collections.synchronizedMap(map m);

  Was this answer useful?  Yes

EshaPrasad

  • Apr 21st, 2009
 

We can do as given below

HashMap hm = new HashMap();
HashMap hm2 = (HashMap)Collections.synchronizedMap(hm);
ArrayList a1 = new ArrayList();
ArrayList a2 = (ArrayList)Collections.synchronizedList(a1);


or in a single line


ArrayList a3 =(ArrayList)Collections.synchronizedList(new ArrayList());


  Was this answer useful?  Yes

pitu2000

  • Aug 21st, 2010
 

After introduction of concurrency api in Java 1.5 we have one more way to synchronize a hashmap
>> new java.util.concurrent.ConcurrentHashMap(hashmapObj);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions