All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.samples.java.ex.SCI_Sample Maven / Gradle / Ivy

Go to download

An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.

There is a newer version: 7.6.8
Show newest version
package ex;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

public class SCI_Sample {
    public Set s = Collections.synchronizedSet(new HashSet());

    public void testSyncMember() {
        Iterator it = s.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public void testSyncKeySetLocal() {
        Map m = Collections.synchronizedMap(new HashMap());
        Iterator it = m.keySet().iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public void testSyncEntrySetLocal() {
        Map m = Collections.synchronizedMap(new HashMap());
        Iterator> it = m.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = it.next();
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }

    public void testSyncValueSetLocal() {
        Map m = Collections.synchronizedMap(new HashMap());
        Iterator it = m.values().iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public void testSyncListLocal() {
        List l = Collections.synchronizedList(new ArrayList());
        Iterator it = l.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public void testSyncSortedSetLocal() {
        SortedSet ss = Collections.synchronizedSortedSet(new TreeSet());
        Iterator it = ss.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    public void testSyncSortedMapLocal() {
        SortedMap sm = Collections.synchronizedSortedMap(new TreeMap());
        Iterator> it = sm.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = it.next();
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }

    public void testSyncCollectionInSync() {
        SortedMap sm = Collections.synchronizedSortedMap(new TreeMap());
        synchronized (sm) {
            Iterator> it = sm.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = it.next();
                System.out.println(entry.getKey() + "=" + entry.getValue());
            }
        }
    }

    public void testSyncCollectionInOtherSync() {
        SortedMap sm = Collections.synchronizedSortedMap(new TreeMap());
        synchronized (this) {
            Iterator> it = sm.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = it.next();
                System.out.println(entry.getKey() + "=" + entry.getValue());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy