Wednesday, June 3, 2015

Synchronization in Java

Each Java Virtual Machine executes many threads at once. All threads execute their internal code and operate their values in a shared memory space.
As we know, Synchronization is a process which executes only one thread at a time. To Synchronize, Java programming language uses monitors which is used to allow only one thread at a time to execute a region of code.
Monitors explained in terms of locks. The synchronized statement performs two special actions relevant only to multithreaded operation:
  1. after computing a reference to an object but before executing its body, it closes a lock associated with the object.
  2. after execution of the body has completed, either normally or abruptly, it unlocks that same lock
The methods wait, notify, and notifyAll of class Object support an efficient transfer of control from one thread to another.
Please see another article: Difference between JRE and JDK for further clarification of Java.

No comments: