Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Why does applet sometimes receive a ThreadDeath Error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does applet sometimes receive a ThreadDeath Error?



A couple of ideas... Perhaps someone smarter than me can tell if these would help :-)
- write your code so that your threads have a way for you to ask them to stop, and write your applet's destroy() so that it asks them to stop, and then waits until they have, before it returns.  This would make it so that by the runtime wants your thread group to go away, all your threads will have already stopped.
- write your code so that it creates it own ThreadGroup to put your threads into, then write your applet's destroy() to ask your threads to stop.  This time, it need not wait for them to actually stop - the idea would be that because they are in a different thread group, they will not be affected by your applet's destruction - but they will stop eventually on their own.

These are both workarounds, in that I don't know why you see the behavior you do...  (Though I am surprised by the sequence of calls you report...).

Moises

P.S> As to why they call Thread.stop() - I am not sure there is an alternative, if the threads are still running...  But this is why my suggestions above - to make sure they are not, anymore, (more) cleanly :-)

On 9/26/06, Rob Lockstone <email@hidden> wrote:

I have a fairly simple applet that does use some fairly complex,
multi-threaded code. The problem is that when the page where the
applet resides is reloaded, it sometimes hangs the entire browser.
I've tracked this down to the point of knowing that a ThreadDeath
Error is being thrown. Here is the stack trace:

java.lang.ThreadDeath
        at java.lang.Thread.stop(Thread.java:716)
        at java.lang.ThreadGroup.stopOrSuspend(ThreadGroup.java:671)
        at java.lang.ThreadGroup.stopOrSuspend (ThreadGroup.java:681)
        at java.lang.ThreadGroup.stopOrSuspend(ThreadGroup.java:681)
        at java.lang.ThreadGroup.stop(ThreadGroup.java:584)
        at sun.awt.AppContext.dispose(AppContext.java:420)
        at sun.applet.AppletClassLoader.release(AppletClassLoader.java:711)
        at sun.plugin.security.PluginClassLoader.release
(PluginClassLoader.java:438)
        at sun.applet.AppletPanel.release(AppletPanel.java :175)
        at sun.applet.AppletPanel.sendEvent(AppletPanel.java:273)
        at sun.plugin.AppletViewer.onPrivateClose(AppletViewer.java:850)
        at sun.plugin.AppletViewer$2.run(AppletViewer.java:812)
        at java.lang.Thread.run(Thread.java:613)

I have a couple questions:

1. Given that Sun deprecated Thread.stop() ages ago, why are Sun
themselves calling the stop method?

2. According to the debugging I've been able to do, this ThreadDeath
error is being thrown ON A NEWLY CREATED thread AFTER the applet has
already completely reloaded and is actually running. This whole
process of shutting down the applet and then reloading it takes less
than two seconds. I'm just reloading the page. The breakdown is: The
applet is stopped via stop(), then destroyed via destroy(). My
threads are shut down. The page reloads, and the applet reloads,
running its init() and start() methods. The applet starts running and
then *boom*, maybe 20% of the time it gets a ThreadDeath error. This
makes no sense to me. The threads from the previous incarnation of
the applet HAVE been cleaned up and have gone away. So why does JVM
send this ThreadDeath Error? And why send it to my newly created
thread which was running along perfectly fine?

Catching and discarding the ThreadDeath error is not an option.
You're not supposed to do that, and besides, I tried and it doesn't
help.

Any thoughts? Thanks.

Rob

_______________________________________________
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Why does applet sometimes receive a ThreadDeath Error? (From: Rob Lockstone <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.