Archived

This topic is now archived and is closed to further replies.

Wrathnut

[java] Java 1.3.1 question

Recommended Posts

I have a quick question about the java 1.3.1 plugin and applets. All of the applets that I have written so far seem to work in all of the browsers I have tested, and for the most part they seem to work in Netscape 6.2, with the exception of when the user closes the browser containing the applet. It seems to actually crash all open browser windows. I think this has to do with the stop() method in my applets. But All it is doing is checking to see if the current thread is running and if it is sets it to null. I remember reading awhile ago on Sun's website that in order to make 1.1 applets compatable with 1.3 applets you need to use the System.exit(0); when killing the applet. But when I try this it throws a security exception. Does anyone have an idea of what's going on. I tried leaving the java console open when I close the applet but It doesn't throw any errors, just locks the browser. BTW here is the code I use to start and stop the applet.
  
public void start(){
    if(runner == null){
            runner = new Thread(this);
            runner.start();
    }
}
	
public void stop(){
    if(runner != null){
            runner.stop();
            runner = null;
    }
}
   
-The cowboys have a way of trussing up a steer or a pugnacious bronco which fixes the brute so that it can neither move nor think. This is the hog-tie, and it is what Euclid did to geometry. Edited by - wrathnut on March 18, 2002 11:16:13 AM

Share this post


Link to post
Share on other sites
Any suggestions for the thread.stop() method to replace it? Otherwise the thread will continue to run in the VM till all browsers are closed.. or atleast that is my understanding. Am I wrong in thinking that? I''m going to try it aynway and see how NS 6 handles it.

-Just when you think things are starting to look up, life grabs you by the jaws makes you open up wide and sh*ts down your throat.

Share this post


Link to post
Share on other sites
I think the correct way to do it is to build a mechanism into the code of the Runnable that makes the run method return when the thread is stopped. Something like this:


  
public void run() {
while(runner != null) {
// Do whatever it is your applet does

}
}

public void stop() {
Thread t = runner;
runner = null;
try {
t.join();
} catch(Interrupted Exception ie) {}
}


You should probably declare your runner field volatile too since it is being read/written by multiple threads. Note that the Thread.stop method is decrapricated and should not be used.

[edited by - HenryAPe on March 20, 2002 1:56:21 PM]

Share this post


Link to post
Share on other sites