🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Notifying a threaded object

#15898
From: Tom Heagy
Date: Tue, 27 Apr 1999 00:00
33 lines
1781 bytes
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: <37261501.64A19494@sciatl.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,9a6ef0837153024c,start
X-Google-Attributes: gidf74b3,public
From: Tom Heagy <tom.heagy@sciatl.com>
Subject: Notifying a threaded object
Date: 1999/04/27
Message-ID: <37261501.64A19494@sciatl.com>
X-Deja-AN: 471590928
Content-Transfer-Encoding: 7bit
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