Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 21 Jul 2011 23:08:07 -0500 Date: Thu, 21 Jul 2011 21:08:05 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Why "lock" functionality is introduced for all the objects? References: <4e28c54c$0$308$14726298@news.sunsite.dk> In-Reply-To: <4e28c54c$0$308$14726298@news.sunsite.dk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 29 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.200.239 X-Trace: sv3-zWG3GP/6yTD0kJyerqrcpuZAVrEVJsbjYv/ocE+CI/mXphdEU2xOHqQatXwgCECPMSPf6rFCnKrcbAy!7QutKE6vLty/lfMSt3MLCJGumx/lXbnRLLDFazpODiMPX5sKXhs7eWyvOtkKnKp9vu/rLJfKP8Ak!OLBKV5dtqNwZV+U4yzQZJYl534wNCE59QHx+avAV/au6wNY= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1924 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6391 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