Synchronized Archive

Static Synchronized Methods

In my previous post, i elaborated object level lock that exist for each instance of a class. We can also use class level lock where all instances of a particular class can share it. As we discussed, any class loaded by java virtual machine has one class level lock. If we make a method static

Synchronized methods and blocks -III

Synchronized Blocks It allows execution of arbitrary code to be synchronized with lock of an arbitrary object. Once a thread reached on synchronized code block after acquiring lock on specified object, other threads will not be able to execute code block or any code requiring same object lock until it is not released by current

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