~/ 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/e2581eb0-6bac-4452-bc1c-018638c166da/flashcard utf-8 LF