~/ learn/ java-from-zero/ cards/ Thread safety: synchronized, volatile & atomic
1 of 4

Type a synchronized increment method

Type a synchronized increment method

Answer

private int count = 0; public synchronized void increment() { count++; }

synchronized on a method uses `this` as the monitor. Only one thread at a time can execute any synchronized method on the same Counter instance.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/bf4a596f-f0da-4a21-bcba-f2e1f61f1721/flashcard utf-8 LF