|
|
Knowledge Base/Java/General
From The Thalesians
[edit]
How to deal with java.lang.OutOfMemoryError: Java heap space
To increase the heap space, pass the following parameters to the JRE:
java -Xms524288 - Xmx1073741824
-Xms specifies the initial Java heap size. -Xmx specifies the maximum Java heap size. The values supplied are in bytes. If the -Xmx is exceeded, an OutOfMemoryError will be thrown.
[edit]
Stack trace as a String
The printStackTrace() method of Throwable (a parent of Exception) will send the stack trace to System.err. As of Java 1.4, getStackTrace() will return the stack trace as StackTraceElement[]. But what if a simple String is needed?
The easiest thing to do is to use yet another method, printStackTrace(PrintStream s), and convert its output to a String, as follows:
t.printStackTrace(printWriter); return result.toString(); }
