Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6400

Re: Why "lock" functionality is introduced for all the objects?

Date 2011-07-22 10:20 -0400
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Why "lock" functionality is introduced for all the objects?
References <d0bb9e06-16f0-4282-a37e-47e9ca9630ec@r2g2000vbj.googlegroups.com> <4e28c54c$0$308$14726298@news.sunsite.dk> <aPydnWItsNg6arXTnZ2dnUVZ_qydnZ2d@earthlink.com>
Message-ID <4e298716$0$315$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source

Show all headers | View raw


On 7/22/2011 12:08 AM, Patricia Shanahan wrote:
> On 7/21/2011 5:33 PM, Arne Vajhøj wrote:
> ...
>> For all the simple cases:
>>
>> public class Foobar {
>> ...
>> private Object lock = new Object();
>> ...
>> public void test() {
>> ...
>> synchronized(lock) {
>> ...
>> }
>> ...
>> }
>> ...
>> }
>>
>> having to use LockingObject instead of Object would have worked fine.
>>
>> But in more complex scenarios where you have multiple methods modifying
>> multiple objects, then the only safe way is to lock on the actual
>> objects (obviously in a fixed order to avoid deadlocks).
>
> I'm not sure how that would have worked for synchronized methods, as
> distinct from synchronized blocks.

It does not.

Synchronized methods are only for the simple cases.

Arne

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

Re: Why "lock" functionality is introduced for all the objects? Arne Vajhøj <arne@vajhoej.dk> - 2011-07-21 20:33 -0400
  Re: Why "lock" functionality is introduced for all the objects? Patricia Shanahan <pats@acm.org> - 2011-07-21 21:08 -0700
    Re: Why "lock" functionality is introduced for all the objects? Arne Vajhøj <arne@vajhoej.dk> - 2011-07-22 10:20 -0400

csiph-web