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.
In this code below, I have made the myMethod() synchronized, expecting that whichever thread executes it would not be interrupted by some other thread. But well, it is not happening so... What should I do in this to achieve synchronization?
Hi I think the point is you're not obtaining what you want because you are not synchronizing the same object, but two different ones. That means that thread a's myMethod will be locked for every object accessing it (that is, just a itself), and the same goes for b's myMethod. Two different instances = two different locks. Try with this (a little strange, I know):
That means, two different threads accessing the same Runnable instance. Hope this helps Regards LR [ December 10, 2007: Message edited by: Luca Romanello ]
Joined: Jun 04, 2007
Thanks a lot, Luca. And finally, I am understanding this... Thanks again...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com