• August 29, 2014
  • Core Java
  • Comments Off on Synchronization in java

Synchronization in java

Synchronization:

Synchronization is a process of controlling mutual exclusive problem in multithreading environment. Only one thread can access a resource at a particular instance of time. When a thread accesses a synchronized block or method, it acquires a lock on it and release the lock either after completion of method/block or any exception occur.

Note:
  1. 1. Synchronization in java is not needed in case of immutable objects.
  2. 2. Synchronized keyword is used for performing synchronization in java.
  3. 3. Variables can’t be synchronized in java. It will give compile time error.

How to implement Synchronization:

  1. 1. Using synchronized method.
    1. a. Using non-static synchronized method.
    2. b. static synchronized method.
  2. 2. Using synchronized block.

 
Next Topic: Synchronized method in java with example.
Previous Topic: Inter-thread communication in java with example.

Related Topics:

Multithreading in java.
Thread life cycle in java.
Way of creating thread in java.
Commonly used methods of Thread class.
Thread scheduling in java with example.
Thread priority in java with example.
Naming a thread in java with example.
Joining a thread in java with example.
Daemon thread in java with example.
Can we start a thread twice?
Can we call run method directly?
Difference between Thread.yield() and Thread.sleep() methods.
Deadlock in java with example.
Starvation in java with example.
Inter-thread communication in java with example.
Synchronization in java with example.
Synchronized method in java with example.
Static synchronization in java with example.
Synchronized block in java with example.

 


Comments are closed.