🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15723

Re: Let sleeping threads lie?

#15723
From: Tad Frysinger
Date: Mon, 03 May 1999 00:00
40 lines
2384 bytes
In article <7gdrkh$ro224@forums.borland.com>, mlong@ecst.csuchico.edu 
says...
> When a thread gets exclusive access to a synchronized "monitor" method, and
> that monitor cannot complete, for whaterver reason, the request of the
> thread, the thread is put to sleep by a call to wait().  If many threads
> have been put to sleep, they are put into a waiting queue.  notify() wakes a
> randomly chosen thread.  If something happens where that thread cannot
> proceed the system can deadlock.  notifyAll() wakes all waiting threads and
> if one cannot proceed, all the others are waiting execute.  Simple rule of
> thumb that I use, and that is presented in Core Java, is to ensure that
> every wait() is matched up with a notifyAll() which seems to work well for
> me.  Of course, if you are positive that all waiting threads are capable of
> completing then this is all academic and notify() is fine.
> 
> Check out Core Java, Volume II, page 107.
> 
> Tad Frysinger wrote in message ...
> >In article <7g65lk$ksf4@forums.borland.com>, mlong@ecst.csuchico.edu
> >says...
> >> Just an addendum to what Chris said on this subject.  It is not really
> >> advisable to us notify(), it can lead to deadlocks if no thread is ready
> to
> >> activate.  notifyAll() notify's all threads that the action has
> completed.
> >> For what it's worth.
> >>
> >I'm interested in this - how can this lead to deadlocks?
> >
> >Tad Frysinger (TeamB)
> 
> 
> 
Ah..  I misunderstood.  I was trying to figure out in a scenario in which 
I had a single thread I was waking up with a call to notify() how this 
might be an issue.

You bring up an interesting point where multiple threads are concerned, 
however...

Tad Frysinger (TeamB)
Technical Details
Message-ID: <MPG.1197e78381ce198f9899d7@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37261640.457FA257@sciatl.com> <37262022.3697507684@forums.borland.com> <37262668.3C79A815@sciatl.com> <7g65lk$ksf4@forums.borland.com> <MPG.1193bc718db4ad7b9899d4@forums.borland.com> <7gdrkh$ro224@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,efa12c4b85d88a4c
X-Google-Attributes: gidf74b3,public
From: tfrysinger@earthlink.net (Tad Frysinger)
Subject: Re: Let sleeping threads lie?
Date: 1999/05/03
Message-ID: <MPG.1197e78381ce198f9899d7@forums.borland.com>
X-Deja-AN: 473701770
References: <37261640.457FA257@sciatl.com> <37262022.3697507684@forums.borland.com> <37262668.3C79A815@sciatl.com> <7g65lk$ksf4@forums.borland.com> <MPG.1193bc718db4ad7b9899d4@forums.borland.com> <7gdrkh$ro224@forums.borland.com>
Organization: Freezone Enterprises
Newsgroups: borland.public.jbuilder.java.language