Answer by Andrew Whitfield (4934) | Jul 07, 2014 at 06:19 AM
The Liberty for Java runtime uses the IBM JRE so you can set the IBM_JAVA_OPTIONS
environment property that can control the type of diagnostics to create (heapdump, javacore, verbosegc etc) and when to create it (uncaught exception, crash, OOM error etc).
For example, to generate a javacore when a a certain exception is thrown (com.my.exception.class in this case) set the following user-defined environment variable (via ACE or CF):
Name: IBM_JAVA_OPTIONS
Value: -Xdump:java:events=throw,filter=com/my/exception/class -Xdump:tool:events=throw,filter=com/my/exception/class,opts=ASYNC,exec="/app/.liberty/bin/server dump defaultServer" -Xdump:what
The javacore should then be generated in this location:
/app/.liberty/usr/servers/defaultServer/
The above will also work for IBM Java buildpacks as the -Xdump options are part of the standard IBM JRE.
Answer by Rohit Kelapure (1001) | Jul 07, 2014 at 08:19 AM
The easiest way to do this is to use the Runtime Management Utility
To do this, select a Liberty application in the user interface. Under Runtime in the navigation on the left, you can open the instance details. Select an instance or multiple instances. Under the Actions menu, you can choose TRACE or DUMP.
Answer by Peter Broadhurst (359) | Sep 25, 2014 at 05:08 PM
You could push a servlet with the following code:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
try {
Class<?> dumper = Class.forName("com.ibm.jvm.Dump");
Method javadump = dumper.getDeclaredMethod("JavaDump", new Class<?>[]{});
javadump.invoke((Object[])null, (Object[])null);
out.println("Javacore dumped. See cf logs for location");
}
catch (Exception e) {
e.printStackTrace(out);
}
}
Answer by Ram Vennam (2928) | Jul 07, 2014 at 08:43 AM
This is not what you asked, but you might find it relevant: https://developer.ibm.com/bluemix/2014/06/18/collecting-diagnostics-crash-2/
Answer by takehiko.amano (4219) | Jul 07, 2014 at 02:51 AM
If you are running IBM Java, send the "kill -3". I believe this will not terminate JVM. But will produce javacore.XXX.txt.
Then your javacore.XXX.txt can be downloaded via.
cf files <app-name> <path-to-corefile>/javacore.XXX.txt > javacore.txt
Not sure about heapdump. Note if your application is get terminated, then your files system on the VM will be gone too. Heal Manager will invoke another VM instance which is probably in healthy status (no core, no heapdump).
Another person may have suggestion to create heapdump while the application is running.
I don't think there is a way to send a 'kill -3' to the app directly. Some of the other answers posted will have to be used.