This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Using the same lock in synchronized()
Posted by Ylian Saint-Hilaire on 29 Jul 1998, 7:02 AM
I am not sure, but I am guessing that the following example will only allow one thread in ONE OF THE SECTIONS at one given time. Since the example uses the same lock object to all the sections. Do I understand currectly? void someUnsynchMethod() { synchronized(this) { do some critical section stuff; } do something piddly that isn't a critical section; synchronized(this) { do some more critical section stuff; } do something else piddly that isn't a critical section; synchronized(this) { do some more critical section stuff; } do something else piddly that isn't a critical section; synchronized(this) { do some more critical section stuff; } }
Replies:
|