🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Java Wait and Notify - Advice?

#17382
From: Max Polk
Date: Mon, 16 Nov 1998 00:00
32 lines
2178 bytes
> When the programme kicks off, the main thread is started as usual and
> proceeds until it hits a Wait()
> at which point the crypto thread takes over. Having completed the
> cryptographic methods, a Notify() is performed on the main thread which duly
> reaquires control (since both threads are the same priority, I assume).
> 
> I assume the crypto thread is still available, but is simply not live. Now,
> I can continue Wait()ing and Notify()ing on the main thread in order to do
> processing in the crypto thread ad infinitum. The question is: what is the
> best way of doing this? It seems to be 'loose' programming to leave a thread
> hanging in this way while the main thread is processing!
> 
> I have looked at Wait()s and Notify()s on the crypto thread itself, but I
> keep coming accross the situation whereby, if I do a Notify() on the main
> thread before the declaration of the Wait() on the crypto thread, the latter
> will never occur.
> 
> Also, if it was essential to do a Wait() and Notify() on the crypto thread,
> how could this be best achieved?

Try creating a new crypto thread each time you need it, and let it run to 
completion.  When it stops, it is *JUST LIKE ANY OTHER OBJECT*.  It is 
not "hanging" like you say.  A thread that returns from the run method is 
no longer running and is simply an object, just like any other object.

Some people like to start such a thread, and after it finishes and the 
main thread wakes up, the main thread can call a method on the stopped 
object and ask it the results.

When you need to start it again, create a new thread.  Provide it with an 
object containing data you need to maintain between crypto thread 
invocations.
Technical Details
Message-ID: <MPG.10ba6f2d92293d6f9896bb@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <72pk2c$qiu21@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,8889eb48cc4dd825
X-Google-Attributes: gidf74b3,public
From: none@none.com (Max Polk)
Subject: Re: Java Wait and Notify - Advice?
Date: 1998/11/16
Message-ID: <MPG.10ba6f2d92293d6f9896bb@forums.borland.com>
X-Deja-AN: 412546172
References: <72pk2c$qiu21@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language