Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java program terminates unexpectedly without any error message

Tags:

java

terminate

I have written a java program which needs to process thousands of text files (all needs to be loaded on memory). It works fine with as many as 123 input files, but when I run it to process around 5000 files, it terminates unexpectedly in the middle of the road, without giving any error message/exception. Can anyone give me clue about what might have gone wrong?

I am using jdk1.6 on Mac OS Leopard having 2GB RAM.

like image 438
Fahim Avatar asked Feb 03 '10 05:02

Fahim


2 Answers

Given that it is your program, I suggest that you do the following:

First, change the main method so that everything is done in a try/catch block that reports all uncaught exceptions; e.g. something like this:

public static void main(String[] arghhhhh) {
    try {
        ...
    } catch (Throwable ex) {
        System.err.println("Uncaught exception - " + ex.getMessage());
        ex.printStackTrace(System.err);
    }
}

Second, look for anywhere that you might "squash" unexpected exceptions by catching them and not reporting them.

Third, look for anywhere that you might call System.exit() silently. This could happen in libraries too ... if you are using a badly written one.

If those measures don't give you answers, try to figure HOW the application is exiting by

  • by running from a debugger with breakpoints set at key points, or
  • by adding trace print statements at key points.
like image 182
Stephen C Avatar answered Oct 13 '22 18:10

Stephen C


It seems like you are getting OutofmemoryError.

if it is the case try to increase heap memory size.

java -Xms<initial heap size> -Xmx<maximum heap size>
like image 21
Upul Bandara Avatar answered Oct 13 '22 18:10

Upul Bandara