Synchronizing a method would mean acquiring a lock to an entire method - and in the cases where synchronizing a block of code is sufficient, it might be a over-kill to synchronize an entire method. The feature for synchronizing a block code will provide the additional flexibility for limiting this process, to a code segment, instead of to an entire method.
Swamy
In the morning there is hope; in the afternoon, fulfillment; in the evening, memory; at night, peace.
Steven Bell
Ranch Hand
Joined: Dec 29, 2004
Posts: 1071
posted
0
In the two cases shown the lock is being aquired on the 'this' instance of the Test class. So I think Ernest is right, there is no difference here.
MK Barman
Greenhorn
Joined: Dec 14, 2004
Posts: 3
posted
0
Yes, Ernest is right. weather you synchronize the method or a block of code inside the method but the monitor is associated with the current instance. [ February 17, 2005: Message edited by: MK Barman ]
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
One small difference is that, if the method is declared synchronized, then that can be seen in the Javadoc. Whereas synchronisation within the method body does not automatically appear in the Javadoc. The run-time behaviour is the same, though.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P