synchronized methods Archive

Synchronized methods and blocks -II

Synchronized Method Synchronize methods are very useful specially when state of an object is changed by class member method which can corrupt object state if executed concurrently. Consider example discussed in previous article, can be found from here, where class counter have two methods increment and decrement. One thread is incrementing whereas other is decrementing

Synchronized methods and blocks -I

Java threads can share resources like memory space etc. Critical situation arise when only one thread at a time have access to shared resources. To handle similar situations, java provides high level concepts for synchronization to control access to shared resources. Locks A lock can be used to synchronize access to shared resources. Any thread