InterviewSolution
| 1. |
What Is The Difference When The Synchronized Keyword Is Applied To A Static Method Or To A Non Static Method? |
|
Answer» When a SYNCH non static method is called a lock is obtained on the OBJECT. When a synch static method is called a lock is obtained on the class and not on the object. The lock on the object and the lock on the class don’t INTERFERE with each other. It means, a thread accessing a synch non static method, then the other thread can ACCESS the synch static method at the same time but can’t access the synch non static method. When a synch non static method is called a lock is obtained on the object. When a synch static method is called a lock is obtained on the class and not on the object. The lock on the object and the lock on the class don’t interfere with each other. It means, a thread accessing a synch non static method, then the other thread can access the synch static method at the same time but can’t access the synch non static method. |
|