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.
This is an instance method of Lock.... so you must invoke it using reference variable of lock only.... [the one you are going to give in "1)" ]
3) After the corrections....The code is definitely synchronized on The object of Lock (Not on TH).... The threads you created in TH (a and b) will try to access the same static Lock object's synchronized method incre...
so, they (a and )b cannot access the incre method at the same time...
i have corrected the code.
karthick 1.Is it that Lock is declared as static due to which,there is synchronization ??
2.if static modifier is removed from the LOCK,then would the code be synchronized ??
In this code if you remove the static modifier of Lock object then each "Th object" will point to a different instance of Lock and
Lock is not even acritical section in that case as no two(or more) threads area accessing the same object......
But you have synchronized your code.....
The point is there will be no need for synchronization in your code if you remove the static modifier of Lock
mohitkumar gupta, Did you get the output which you mentioned in you first post on this thread? Check the below code.
And, There is no relationship with declaring the Lock a as static with the synchronization. It's up to the developer. If you don't declare the Lock a as static, then every TH object will have a separate Lock object. So, logically, the synchronization won't needed. I mean, there is no point of synchronization. Because, two threads, two object.
Use proper indentation in your post. This is said many times, that's why, you don't get the responses.
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