🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Let sleeping threads lie?

#15905
From: Chris Hill
Date: Tue, 27 Apr 1999 00:00
36 lines
2229 bytes
On Tue, 27 Apr 1999 17:04:40 -0400, Tom Heagy <tom.heagy@sciatl.com>
wrote:

>Thanks Chris.  That works like a charm.  Just out of curiosity, could you
>tell me what the intent of "notify" is?  After doing some more reading I'm
>still not clear, but it seems like it may have something to do with objects
>that are blocked due to waiting on a response from another thread???
>
>-Tom

The JDK reference documentation is a bit confusing on this topic.
There is a slightly longer description in the JLS (Java Language
Specification).  The JLS is available in the JBuilder documentation or
on the Sun web site.  Chapter 17 covers threads and locks.  See
sections 17.13 and 17.14 (you will get a headache if you try to read
the entire chapter).

notify, notifyAll, and wait are related to the Java thread
synchronization mechanism.  For example, if you have threads
communicating in a Consumer/Producer relationship, access to the
shared data can be synchronized using notify and wait.  To call
notify, notifyAll, or wait on an object the calling thread must own
the monitor for the object.  A thread aquires the monitor by entering
a synchronized method or statement (these are also described in the
JLS).  All the threads that are waiting on an object are suspended
until another thread calls notify or notifyAll (or there is a wait
timeout).  When a thread calls wait, it also releases the monitor.
When a thread is resumed by the notify call of another thread, it
tries to get the monitor back (it must still compete with other
objects for the monitor), and once it does, it continues. 

I hope this explains the basics.  For the details read the JLS.


Chris Hill
Chris244@aol.com
Technical Details
Message-ID: <37263394.3702485662@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>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,efa12c4b85d88a4c
X-Google-Attributes: gidf74b3,public
From: Chris244@aol.com (Chris Hill)
Subject: Re: Let sleeping threads lie?
Date: 1999/04/27
Message-ID: <37263394.3702485662@forums.borland.com>
X-Deja-AN: 471653704
References: <37261640.457FA257@sciatl.com> <37262022.3697507684@forums.borland.com> <37262668.3C79A815@sciatl.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language