class Counter { private int currentValue = 0; private static Object LOCK = new Object(); public int next() { synchronized(LOCK) { return ++currentValue; } } }