Najděte v následujících třídách chyby v synchronizaci:
class Counter { private static int currentValue = 0; public synchronized int next() { return ++currentValue; } }
class Counter { private int currentValue = 0; private static Object LOCK = new Object(); public int next() { synchronized(LOCK) { return ++currentValue; } } }
public class SomeThreadSafeClass { private List<String> data = Collections.synchronizedList(new ArrayList<String>()); public void addData(String newObject) { data.add(newObject); } public synchronized void dumpData() { for(String s : data) { System.out.println(s); } } }