What Is Synchronization

Q

What do you understand by Synchronization?

✍: FYIcenter

A

Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.

Examples of synchronizing methods or block of codes

public synchronized void myMethod() {
   ...
}
public yourMethod() {
   ...
   synchronized (this) {
      ...
   }
}

2007-03-03, 5106👍, 0💬