...
Explicitly define the name of the class (superclass here) in the synchronization block. This can be achieved in two ways. Onw way is to explicitly pass the superclass's instance.Class.forName()
.
Code Block | ||
---|---|---|
| ||
synchronized(SuperclassName.class) { ... }
|
The second way is to use the Class.forName()
method.
Code Block | ||
---|---|---|
| ||
synchronized(Class.forName("SuperclassName")) { ... }
|
Finally, it is important to recognize the entities with which synchronization is required rather than indiscreetly scavenging for variables or objects to synchronize on.
...