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.
Synchronization in java is not needed in case of immutable objects.
Synchronized keyword is used for performing synchronization in java.
Variables can’t be synchronized in java. It will give compile time error.
How to implement Synchronization:
- Using synchronized method.
- Using synchronized block.
- Multithreading in java.
- Thread life cycle in java.
- Way of creating thread in java.
- Which is a better way to create a thread in java?
- Commonly used methods of Thread class.
- Difference between thread start and run method.
- Why we call start method in thread?
- Can we override start method?
- Can we override run method?
- Can we start a thread twice?
- 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.
- How to get current thread in java?
- Daemon thread in java with example.
- 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.