Thread Synchronization In Java

Synchronization in java is the capability to control the access of multiple threads to any shared resource.Java Synchronization is better option where we want to allow only one thread to access the shared resource.The synchronization is mainly used to
  • To prevent thread interference.
  • To prevent consistency problem.

Types of Synchronization
There are two types of synchronization:
  • Process Synchronization
  • Thread Synchronization

Here, we will discuss only thread synchronization.
Thread Synchronization:
There are two types of thread synchronization mutual exclusive and inter-thread communication.
Java synchronized method:
  1. If you declare any method as synchronized, it is known as synchronized method.
  2. Synchronized method is used to lock an object for any shared resource.
  3. When a thread invokes a synchronized method, it automatically acquires the lock for that object and releases it when the thread completes its task.

Comments

Popular posts from this blog

Flutter : Introduction

Dart: Functions

Firebase Cloud Messaging