Synchronization threads की साझा mutable state तक पहुंच को समन्वित करता है ताकि operations खतरनाक तरीके से interleave न हों, race conditions को रोकता है। Java कई mechanisms प्रदान करता है, built-in synchronized keyword से explicit locks और lock-free atomics तक।
synchronized — mutual exclusion (intrinsic locks)
{
balance;
{
(balance >= amount) {
balance -= amount;
}
}
{
() {
balance += amount;
}
}
}
