Patricia Samuel wrote:There are two threads that are trying to call t1.m1 and t2.m2()... is it possible to call both the method. As per my understanding it is correct as one is class level method. Please give your inputs.
Yes, I believe the lock on the class and the lock on the instance are different.
Patricia Samuel wrote:
Is it possible to call t1.m1() and t2.m2(). Here i think its not. Please correct me if i am wrong.
.
No, once a thread obtains a lock on the instance only
that thread can access ANY synchronized method of that instance.
Try this code:
The output of the above program illustrates these points.
HTH,
Nidhi