Java Reference
In-Depth Information
}
...
public void start () {
if (fMyThread!= null) {
fMyThread.start ();
}
else
fMyThread = new Thread (this);
}
public void stop () {
fMyThread = null;
}
void run () {
while (fMyThread!= null) {
...
}
}
} // MyApplet
Remember that the start() and stop() methods in the Applet class are
unrelated to methods with the same names in the Thread class. Like the init()
method in the Applet class, these are just methods that allow the browser to
control the applet. The browser invokes start() each time the applet page is
loaded (note that init() is only invoked the first time the applet web page is
loaded). The applet's stop() is a good place to do housecleaning such as killing
any live threads. Always explicitly stop your threads in applets when the applet
stop() is called. Otherwise, they may continue running even when the browser
loads a new web page.
Furthermore, do not use the deprecated suspend() and resume() methods
in the Thread class for the same reasons given for not using the stop() method.
Yo u can obtain effective suspend/resume operations by killing the thread (that is,
signaling for it to return safely from the processing in the run() method) and
creating a new one with the same values of the variables as when the previous
thread died. The new thread will then simply continue from where the last one
finished.
8.4 Multiprocessing issues
An operating system executes multiple processes in a manner similar to that
for multithreading except that each process stack refers to a different program
 
Search WWH ::




Custom Search