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