Previous | Next | Trail Map | Writing Applets | Overview of Applets


Threads in Applets: Bad Example

Note: If you've already looked at this page, reload the applet to see the example again.

The following applet (named Bad) does the same things as the Good applet, but at the wrong time: It performs its computation in its init() method. (Here's the source code.) You can watch the applet's progress by reading the status line at the bottom of this window. Notice how the applet (and perhaps the text that follows it) doesn't appear for quite a while. In the 1.0alpha3 HotJava browser, this delay is because the formatting thread is stuck executing the applet's init() method.

Worse yet, the Bad applet, if it were on the same page as the Good one, could starve the Good one. This is browser dependent, and would happen if a browser didn't call the Good applet's start() method until Bad's init() method has returned. When this happened, the Good applet wouldn't get a chance to create its thread (much less run it) until the Bad applet finished.


Previous | Next | Trail Map | Writing Applets | Overview of Applets