public class SyncCounter { private volatile int i = 0; public synchronized void inc() throws InterruptedException { Thread.sleep(6); i++; } public synchronized void dec() throws InterruptedException { Thread.sleep(6); i--; } public synchronized int getI() { return i; } }