Synchronization is a process through which multiple threads share access to common objects. Java coordinates the actions of multiple threads using synchronized methods and statements. Following are the properties of synchronization:
- If a thread contains some locks and goes to sleep, then it does not release the locks.
- Only methods can be synchronized, not variables and constants.
- If two threads invoke the same method, then only one thread at a time can invoke a method.
- A thread can invoke a synchronized method on multiple objects.
- A class can have both synchronized and non-synchronized methods.
- If a class has synchronized and non-synchronized methods, then multiple threads can still access the non-synchronized methods of the class.
No comments:
Post a Comment