Proper Threading

From: Mark Haase (mehaase_at_earthlink.net)
Date: 10/28/03


Date: Tue, 28 Oct 2003 12:12:34 -0500

Hey All--

I've just gotten back into java for a work-study job I have doing some
research. I'm having to refigure out GUI, events, and Threads, since
these have changed significantly since the JDK 1.03 when I used to write
java.

So suspend() and resume() are deprecated now? I can see how they're
dangerous, but why not let programmers assume that danger like any other
threaded runtime environment?

Anyways, what I'm doing now is I have a "running" boolean that tells the
thread whether to do any work, ie:

public void run () {
   while (true) {
      if (running) {
         // do the thread's work
      }
      try {Thread.sleep(100)}
      catch (InterruptedException e) {
         System.out.println("Caught error: " + e.toString());
      }
   }
}

Is this what the makers of Java intended? I feel strange about the while
(true) but this is inside an applet, so I figure that its okay because
the browser will call stop() when its done with the applet, and stop()
always stops the thread.

If this is not ideal, then can somebody point me to a resource that
shows how to do it right?

tia

-- 
|\/|  /|  |2  |<
mehaase(at)sas(dot)upenn(dot)edu


Relevant Pages

  • Re: Image applet with NetBeans IDE
    ... applet to understand how java works and so on... ... my working code for filters and a "professional" gui, ...
    (comp.lang.java.help)
  • Re: Applet problems in adding a bgImage
    ... paste a little of the earlier conversation, so people don't get lost. ... > If you think I should start by writing an app first, then a gui, then ... > an applet, then is there anyway to make it so people can run my gui ... > having to download the Java Runtime Environment? ...
    (comp.lang.java.programmer)
  • Re: Can C++ programming by divided into two levels?
    ... lead to the same situation, simply, because memory is not infinite. ... Other languages like Java, who engage a garbage collector, depend on ... The most challenging danger to my opinion is that, ...
    (comp.lang.cpp)
  • Re: Proper Threading
    ... > I've just gotten back into java for a work-study job I have doing some ... > dangerous, but why not let programmers assume that danger like any other ... > but this is inside an applet, so I figure that its okay because ... Hi Tia, ...
    (comp.lang.java.help)
  • Re: Proper Threading
    ... > I've just gotten back into java for a work-study job I have doing some ... I'm having to refigure out GUI, events, and Threads, since ... > dangerous, but why not let programmers assume that danger like any other ...
    (comp.lang.java.help)