Interview Questions

Suppose you have thread and it is in static synchronized method and now can thread enter other non static synchronized method from that method?

Java Interview Questions and Answers (part 4)


(Continued from previous question...)

46. Suppose you have thread and it is in static synchronized method and now can thread enter other non static synchronized method from that method?

Yes, here when thread is in static synchronized method it must be holding lock on class’s class object and when it enters synchronized method it will hold lock on object’s monitor as well.

So, now thread holds 2 locks (it’s also called nested synchronization)- first one on class’s class object.
second one on object’s monitor (This lock will be released when thread exits non static method).

(Continued on next question...)

Other Interview Questions