[java] Simple Applet Question.

Started by
0 comments, last by Wrathnut 23 years, 11 months ago
HI, I have a simple applet question I was hoping someone could help me with. I just installed communicator 4.72 on my development machine and I noticed that all of my applets, previous ones that worked fine and the current ones were getting an error in the console window.. sometimes they wouldn''t even load up. Apparently it''s running the symantec JIT which supports java 1.1.5, Now I know why my applets are getting messed up. If you are compiling with java 1.1.3 or prior releases you are supposed to add this line at the end of you main() System.exit(0); This is all well and good, it''s an easy fix.. But all of my applets implement runnable interface so I can thread the animations. Anyway I added that line at the end of the stop() function. That fixxed it so my applets would load, but if I try to goto a different page with a different applet or reload that page I get an error in the console that sometimes makes the applet not run. I believe the error is basically "java.lang.illegalMonitorStateException: current thread not owner" Which I''m not sure if I understand... I guess I don''t know enough about threads to fix it. Any input would help. And if anyone would like to see some code I can post that too. War doesn't determine who is right, war determines who is left.
Advertisement
Using java.lang.System.exit(int) in an applet is bad. Don''t do it. Generally what the specs tell you to do to handle Threads is to enclose the body of the thread''s run() method with a while(boolean) {...} statement. like:

public void run() {
while(is_running) {
...
}
}
And so, when you want to stop that thread, set is_running to false. It is like this because the thread''s start() & stop() methods are buggy. So at the end of your applet''s stop() set all the thread control booleans to false, and in the applet''s start() set them to true (you may have to call thread.run() again} and in the destroy() set them all to null, including the current thread, which you can get by doing
Thread t = Thread.currentThread();
t = null;

This topic is closed to new replies.

Advertisement