List of usage examples for java.util Collections synchronizedMap
public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m)
From source file:Main.java
public static void main(String[] args) { HashMap hashMap = new HashMap(); Map map = Collections.synchronizedMap(hashMap); }
From source file:Main.java
public static void main(String[] args) { TreeMap treeMap = new TreeMap(); Map map = Collections.synchronizedMap(treeMap); }
From source file:Main.java
public static void main(String[] args) { // create map Map<String, String> map = new HashMap<String, String>(); // populate the map map.put("1", "A"); map.put("2", "B"); map.put("3", "java2s.com"); // create a synchronized map Map<String, String> synmap = Collections.synchronizedMap(map); System.out.println("Synchronized map is :" + synmap); }
From source file:Main.java
public static void main(String[] args) { Collection<String> c = Collections.synchronizedCollection(new ArrayList<String>()); List<String> list = Collections.synchronizedList(new ArrayList<String>()); Set<String> s = Collections.synchronizedSet(new HashSet<String>()); Map<String, String> m = Collections.synchronizedMap(new HashMap<String, String>()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { final int MAX_ENTRIES = 100; Map cache = new LinkedHashMap(MAX_ENTRIES + 1, .75F, true) { public boolean removeEldestEntry(Map.Entry eldest) { return size() > MAX_ENTRIES; }/*w w w .j a v a 2 s . c o m*/ }; Object key = "key"; Object value = "value"; cache.put(key, value); Object o = cache.get(key); if (o == null && !cache.containsKey(key)) { } cache = (Map) Collections.synchronizedMap(cache); }
From source file:MainClass.java
public static void main(String args[]) { Set simpsons = new HashSet(); simpsons.add("B"); simpsons.add("H"); simpsons.add("L"); simpsons = Collections.synchronizedSet(simpsons); synchronized (simpsons) { Iterator iter = simpsons.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }//w w w .j a va 2 s . co m } Map map = Collections.synchronizedMap(new HashMap(89)); Set set = map.entrySet(); synchronized (map) { Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } } }
From source file:Synchronization.java
public static void main(String[] args) { Collection c = Collections.synchronizedCollection(new ArrayList()); List list = Collections.synchronizedList(new ArrayList()); Set s = Collections.synchronizedSet(new HashSet()); Map m = Collections.synchronizedMap(new HashMap()); }
From source file:SyncTest.java
public static void main(String args[]) { Set simpsons = new HashSet(); simpsons.add("Bart"); simpsons.add("Hugo"); simpsons.add("Lisa"); simpsons.add("Marge"); simpsons.add("Homer"); simpsons.add("Maggie"); simpsons.add("Roy"); simpsons = Collections.synchronizedSet(simpsons); synchronized (simpsons) { Iterator iter = simpsons.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/* w ww . j a v a2 s.c o m*/ } Map map = Collections.synchronizedMap(new HashMap(89)); Set set = map.entrySet(); synchronized (map) { Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } } }
From source file:at.ac.tuwien.infosys.logger.ProvisioningLogger.java
public static void main(String[] args) { Map<String, Log> deviceLogs = Collections.synchronizedMap(new HashMap<String, Log>()); System.out.println(deviceLogs.values().contains(null)); deviceLogs.put("id1", null); System.out.println(deviceLogs.values().contains(null)); }
From source file:Main.java
public static <K, V> HashMap<K, V> synchronizedMap() { return (HashMap<K, V>) Collections.synchronizedMap(new HashMap<K, V>()); }