Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6400
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail |
|---|---|
| Date | Fri, 22 Jul 2011 10:20:02 -0400 |
| From | Arne Vajhøj <arne@vajhoej.dk> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; 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 | <d0bb9e06-16f0-4282-a37e-47e9ca9630ec@r2g2000vbj.googlegroups.com> <4e28c54c$0$308$14726298@news.sunsite.dk> <aPydnWItsNg6arXTnZ2dnUVZ_qydnZ2d@earthlink.com> |
| In-Reply-To | <aPydnWItsNg6arXTnZ2dnUVZ_qydnZ2d@earthlink.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Lines | 35 |
| Message-ID | <4e298716$0$315$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
| NNTP-Posting-Host | 72.192.23.157 |
| X-Trace | news.sunsite.dk DXC=7f_^G3WBaNe5kL0JZ2<WfiYSB=nbEKnkk4ang]8e?Co`JPe3\kP5EUaKBm9cfh9BSdM2;kT<[:>[a\``R3S_F;3gPTIYKm:f0_o |
| X-Complaints-To | staff@sunsite.dk |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6400 |
Show key headers only | 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 | Next — Previous in thread | Find similar
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