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


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

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

Date 2011-07-21 21:08 -0700
From Patricia Shanahan <pats@acm.org>
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>
Message-ID <aPydnWItsNg6arXTnZ2dnUVZ_qydnZ2d@earthlink.com> (permalink)

Show all headers | View raw


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.

Patricia

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next 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