Java applet hangs randomly in Linux; how can I identify the cause?

I have a java applet which mostly runs fine. However, when used in Linux, it sometimes hangs. The exact behaviour is this:
1. After repeating the same exact action in the applet for a number of times, the applet stops responding.
2. The browser (Firefox) still works; however, to be able to use java plugins again, Firefox must be restarted AND the java_vm process must be manually killed.
3. No errors are reported in the log files. Tracing, logging and "applet lifecycle expectations" are all enabled.
4. The java_vm takes up a lot of cpu when it hangs, so I guess that it gets stuck in a loop.

My questions:

How can I identify the problem?

Is there some way to log the activities of java in more detail so as to understand at what point the error occurs?

Is there perhaps some known "bug" - that is, some piece of java code which causes applets to hang under Linux?

I myself run Ubuntu Feisty with Java, but several Linux users have reported the same problem.

The end of my log file looks like this:
  <message>redrawing boardlayer

The end of the trace file says (repeated about 15 times in all):
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
redrawing boardlayer
Who is Participating?
Have you tried putting debugging info in your logs to trace the root cause of the problem?
try printing the dump on the applet console, which will give the details of currently executing code and its state!

to print the dump, open the console, press 'l'
Ok - here is what I have done in these situations.  First make sure that the java console is enabled for Firefox (which it probably is) - then put in a bunch of System.out.println()'s to create your own output to the console when the applet is running.  

When the applet is running and its stuck in a loop somewhere you won't get any output to the log or console unless you create some yourself.  As far as the JVM is concerned its working just like it was programmed (even if there is an error).

Here's an example:

for (int i=0; i<100; i--) {
  // Do some work
  x = x +1;
// output a line to the system console
  System.out.println(" inside i loop, current value is " + i );

If you do something like the above you will get a series of system out's in the console and you can narrow down where your error is, in my experience once you find where it is, its pretty easy to get the answer or ask another more specific question.

Also note  - my example above creates a nice infinite loop!
One more comment - start out with a small numerb of System.out's that cover the entire section of the applet that appears to be a problem.  Then create additional system.out's in your code to narrow down where the error is occuring.  You may find its either your code or part of a call to the JVM, but an iterative approach will zero in on the issue.
Did any of the ideas above work for you?  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.