This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
can any one please help me with this,"A thread can aquire more than one lock" how a thread does that...
like it gets starter by
then it calls the run method, which calls a synchronized method .now it hold a lock on an object implementing the runnable or extending the thread class.now how does the same thread gets a lock on another object.
how do I reinitialize the same thread with the new runnable object.
It will not hold the lock of object which implements the runnable interface instead of it, it will hold the lock of the object whose synchronized method is being called.
If an object is having a synchronized method and that method is being called from the Thread then the thread first have to hold the lock then only the method can be executed.
A thread can hold the locks on multiple objects, if there are two different objects which are having synchronized methods and the synchronized method of one class is calling the synchronized method of another class. In this case the calling class must have the lock on both the objects.
Hope this will help and correct me if i am wrong.