How to reload applet from inside the applet?
Posted on 1997-10-06
My applet has trouble executing under Netscape browser. The browser starts executing the init() method and hangs somewhere before finishing it (no error messages or exceptions). As a result the applet's GUI does not get displayed. I was trying to find the reason why the applet hangs but this question is about a different issue.
I noticed that if I reload the hung applet using browser's Reload button (or simply switch to a different page and then come back to the original applet) the applet executes normally. (Browser starts executing init() again and this time finishes it).
My question is whether it is possible to simulate this behavior from within an applet. I cannot use getAppletContext().showDocumnent() since the HTML file for this applet gets build dynamically and does not exist on disk.
What I did was to create a new class RestartApplet() which extended Thread. At the beginning of init() method I created new instance of that class passing it an applet as an argument and call its start() method (start a thread). At the end of init() that thread gets killed.
That thread sleeps for N seconds and then (if its still alive which means init() never finished) tries to restart an applet. I do it by executing the following code:
That works fine in AppletViewer but does not quite work in Communicator.
Question is: what is the appropraite way to reload an applet from inside (so that the browser new that it is reloaded) given the restrictions described above.