'Understanding Synchronized block with "this" object reference
One way to synchronize multiple threads in java is through the usage of synchronized blocks.
synchronized (this){// code to sync.}
I am trying to understand more the synchronized (this) . There are similar question here for this part but neither with a detailed answer for me. I need to check my understanding. The "this" keyword refers to the instance that through which we are calling the method. In other words , if we are calling the method with two threads objects through the same object , then "this" keyword in every thread will refer to same object they are using. However , if the two threads are using two different object of the same class , then "this" keyword in every thread will refer to a different object and there will be no synchronization between them. Is that right ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
