Using the Collections.synchronized methods : General Collections « Collections Data Structure « Java






Using the Collections.synchronized methods

// : c11:Synchronization.java
// Using the Collections.synchronized methods.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Synchronization {
  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());
  }
} ///:~



           
       








Related examples in the same category

1.Collections: List, Set, SortedSet, LinkedHashSet, Map, LinkedHashMapCollections: List, Set, SortedSet, LinkedHashSet, Map, LinkedHashMap
2.Sometimes methods defined in the Collection interfaces don't workSometimes methods defined in the Collection interfaces don't work
3.Simple demonstrations of the Collections utilitiesSimple demonstrations of the Collections utilities