<<< Example: Counter class sample output | Index | The synchronized methods example >>> |
The synchronized keyword can be used to mark four different types of blocks:
Instance methods
Static methods
Code blocks inside instance methods
Code blocks inside static methods
The idea: When one thread is executing a synchronized method, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
<<< Example: Counter class sample output | Index | The synchronized methods example >>> |