Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
public class SCI_Sample {
    public Set<Strings = Collections.synchronizedSet(new HashSet<String>());
    public void testSyncMember() {
        Iterator<Stringit = .iterator();
        while (it.hasNext()) {
            ..println(it.next());
        }
    }
    public void testSyncKeySetLocal() {
        Map<StringStringm = Collections.synchronizedMap(new HashMap<StringString>());
        Iterator<Stringit = m.keySet().iterator();
        while (it.hasNext()) {
            ..println(it.next());
        }
    }
    public void testSyncEntrySetLocal() {
        Map<StringStringm = Collections.synchronizedMap(new HashMap<StringString>());
        Iterator<Map.Entry<StringString>> it = m.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<StringStringentry = it.next();
            ..println(entry.getKey() + "=" + entry.getValue());
        }
    }
    public void testSyncValueSetLocal() {
        Map<StringStringm = Collections.synchronizedMap(new HashMap<StringString>());
        Iterator<Stringit = m.values().iterator();
        while (it.hasNext()) {
            ..println(it.next());
        }
    }
    public void testSyncListLocal() {
        List<Stringl = Collections.synchronizedList(new ArrayList<String>());
        Iterator<Stringit = l.iterator();
        while (it.hasNext()) {
            ..println(it.next());
        }
    }
    public void testSyncSortedSetLocal() {
        SortedSet<Stringss = Collections.synchronizedSortedSet(new TreeSet<String>());
        Iterator<Stringit = ss.iterator();
        while (it.hasNext()) {
            ..println(it.next());
        }
    }
    public void testSyncSortedMapLocal() {
        SortedMap<StringStringsm = Collections.synchronizedSortedMap(new TreeMap<StringString>());
        Iterator<Map.Entry<StringString>> it = sm.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<StringStringentry = it.next();
            ..println(entry.getKey() + "=" + entry.getValue());
        }
    }
    public void testSyncCollectionInSync() {
        SortedMap<StringStringsm = Collections.synchronizedSortedMap(new TreeMap<StringString>());
        synchronized (sm) {
            Iterator<Map.Entry<StringString>> it = sm.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<StringStringentry = it.next();
                ..println(entry.getKey() + "=" + entry.getValue());
            }
        }
    }
    public void testSyncCollectionInOtherSync() {
        SortedMap<StringStringsm = Collections.synchronizedSortedMap(new TreeMap<StringString>());
        synchronized (this) {
            Iterator<Map.Entry<StringString>> it = sm.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<StringStringentry = it.next();
                ..println(entry.getKey() + "=" + entry.getValue());
            }
        }
    }
New to GrepCode? Check out our FAQ X