Wednesday, 16 October 2013

How to make Map As Synchronized



import java.util.HashMap;
import java.util.Collections;
import java.util.Map;

public class SyncronizedMapExample {

  public static void main(String[] args) {
    //create HashMap object
    HashMap hashMap = new HashMap();
 
    /*
      Java HashMap is NOT synchronized. To get synchronized Map from
      HashMap use
      static void synchronizedMap(Map map) method of Collections class.
    */
 
    Map map = Collections.synchronizedMap(hashMap);
 
    /*
       Use this map object to prevent any unsynchronized access to original
       HashMap object.
    */
 
  }
}

No comments:

Post a Comment

Very Impotent Links for Java and Portal development development

Jar Download for Spring  Maven Or Gradel Dependency for Spring