src.samples.java.ex.SCI_Sample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fb-contrib Show documentation
Show all versions of fb-contrib Show documentation
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.
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());
}
}
}
}