Home >Java >javaTutorial >How to use java synchronization method
1. For ordinary synchronization methods, the lock will be associated with the object that calls the method.
2. For static synchronization methods, the lock is a monitor related to the declaring method class object.
3. The easiest way to create a synchronized block is to declare the method as synchronized.
This means that the caller must acquire the lock before entering the method body.
Example
public class Point { public synchronized void setXY(int x, int y) { this.x = x; this.y = y; } }
The above is the detailed content of How to use java synchronization method. For more information, please follow other related articles on the PHP Chinese website!