Article View: borland.public.jbuilder.java.language
Article #15901Re: Let sleeping threads lie?
From: Tom Heagy
Date: Tue, 27 Apr 1999 00:00
Date: Tue, 27 Apr 1999 00:00
38 lines
2002 bytes
2002 bytes
SORRY- This is a duplicate of a previous message. I didn't think the first
one made it through.
Tom Heagy wrote:
> I'm trying to find a way to wake up a sleeping thread and I'm missing
> something that is probably obvious to someone else.
>
> I have a little test project where I've created an object (Sleeper) that
> extends "Thread" and does nothing more than the following in it's run
> method:
>
> while (true) {
> System.out.println("I'm going to sleep for 10 seconds.");
> try {
> Thread.sleep(10000);
> }
> catch (InterruptedException e) {
> System.out.println("My sleep was interrupted.");
> }
> System.out.println("I'm awake!!");
> }
>
> Nothing special here and this obviously works as desired. It wakes up
> every 10 seconds and prints it's messages. Now, my problem comes into
> play when I want to wake up the thread BEFORE it does itself. I thought
> this was possible through the "notify" method. I have another class
> (with a Main method) that instantiates a Sleeper object and executes the
> "notify" method when a user clicks a button. When I do this however, I
> get the message that states "Current thread not owner".
>
> I guess my bottom line is- "How do I become the owner of this thread?"
> I own the original handle to the sleeper object. What else do I need to
> do?
>
> Thanks in advance for your input.
>
> -Tom
Technical Details
Message-ID:
<3726175A.C1EE4FBC@sciatl.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<37261640.457FA257@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: Tom Heagy <tom.heagy@sciatl.com> Subject: Re: Let sleeping threads lie? Date: 1999/04/27 Message-ID: <3726175A.C1EE4FBC@sciatl.com> X-Deja-AN: 471590931 Content-Transfer-Encoding: 7bit References: <37261640.457FA257@sciatl.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language