InterruptApplet - Demo of interrupt() in applets
Some browsers built-in Java VM's do not properly notice
when a thread is interrupted (using the interrupt() method
of Thread.
This applet tests for and
demonstrates that behavior. As of Netscape 4.7, the
interrupt() method has still not been properly
implemented. However, Internet Explorer 5 does implement
interrupt() correctly. You can press the different buttons
below to check out your browser's implementation.
Start up the clock thread by pressing the "Start Clock Thread" button.
To check if your broswer's VM implements interrupt()
correctly, press the "Interrupt Clock Thread" button. If this
successfully stops the clock's internal thread by triggering an
InterruptedException, the clock time is replaced with
the message "STOPPED - by InterruptedException". If your browser does
not implement interrupt() correctly, the clock will keep
running. You can then try the third button so set a looping flag and
interrupt the thread--this should work for everyone.
For more on threads and Java, check out great book
Java Thread Programming.
See
Chapter 5 in particular
for an explanation of the interrupt() method.