Synchronization ले threads को साझा mutable state मा पहुँचलाई समन्वय गर्छ ताकि operations खतरनाक तरिकाले आपस मा न मिसिन, 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;
}
}
}
