[2075] in java-interest

home help back first fref pref prev next nref lref last post

Re: Wouldn't it be nice if...

daemon@ATHENA.MIT.EDU (Andrew Wason)
Fri Sep 22 19:58:55 1995

To: java-interest@java.sun.com
In-Reply-To: Message from rethingt@lehman.com (Russell Ethington) 
   of "Fri, 22 Sep 95 10:36:11 -0400."   <9509221436.AA11973@fiadevnm1.lehman.com> 
Date: Fri, 22 Sep 95 17:15:33 -0400
From: Andrew Wason <aw@bae.bellcore.com>

rethingt@lehman.com (Russell Ethington)  writes:
> I just learned that putting an Applet thread to sleep in the wrong
> place can block other Applets of the same kind. For example:
> 
> // ...
>    Thread life;
>    // ...
>    public void paint() {
>       for (int i = 0; i < 100; i++) {
> 		   // ...
>          life.sleep(50);
>       }
>    }

Remember, Thread.sleep() is a static method which puts the
*currently executing thread* to sleep.  Even though you are
invoking it through the "life" instance, it will put the
currently executing thread to sleep (which may not be the "life"
thread).

Your applets paint() method was probably being run in the "AWT
WServer Thread", and so you put that thread to sleep.  So no one
(not even the browser) was getting events until it woke up.

You can see which threads are calling which methods by sticking a
debug print in your method:

  System.out.println("paint() " + Thread.currentThread().getName());


Andrew

_______________________________________________________________________________

Andrew Wason                                       Bell Communications Research
aw@bae.bellcore.com                                Piscataway, NJ
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post