Home >Java >javaTutorial >Java dumps
Java Dumps are some Java cores that get created mistakenly when the Virtual Machine gets a halt unexpectedly due to network issues, Memory error, or when the user initiates any type of keystroke combination. A Java Dump can be created easily either by calling the Java Dump API being incorporated into the source code of the application or by directly providing the -Xdump:java option through the command line. Java Dump provides aid to the end-user by providing some useful information for troubleshooting and diagnosing the root cause of the halt that occurs when the application stops running unexpectedly.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax
There is no specific syntax for Java dumps as the need for java dumps depends upon the root cause of the problem, which can be varied, as mentioned. So, this syntax flow is when the user needs to diagnose the root cause and want to perform analysis using the jcmd tools just by sending required requests to the JVM, and it is mandatory to use the same system at the runtime which is used for sending this request to the machine and the Java program. So, the Syntax is defined as follows:
jcmd <process_ id> GC.heap_dump <pathname_for_file>
where the parameters passed are :
Workflow for Java Dumps is very interesting with the fact that it provides a huge aid to the end-user or the programmer at the time of machine crash or any unexpected halt in the system due to varied reasons being mentioned like network outage, memory error, etc. Furthermore, any form of error hindering the Java program execution can be saved by using java Dumps for troubleshooting and diagnosis of the root cause. There are some scenarios based on which Dumps in Java works which are as follows :
There are different ways to capture all the scenarios and their root cause by using Java dumps tools and technologies. They are very useful in troubleshooting memory leakage related problems and memory optimization problems. They are mostly stored in the binary formats in hprof files that can be visualized and analyzed using the following tools and technologies like :
This Example Demonstrates the thread performing deadlock on the resources, and now that they have acquired the locks on the resources there is a possibility of analysis of this deadlock on the resources with Java Dumps using the command in the command line mention.
public class Java_lock_Dump_Demo { public static void main(String[] args) throws InterruptedException { Object ob_a = new Object(); Object ob_b = new Object(); Object ob_c = new Object(); Thread Java_lock_Dump_DemoThread1 = new Thread (new Java_lock_Dump_Demo_Sync_Thread(ob_a, ob_b ), "Java_lock_Dump_DemoThread1"); Thread Java_lock_Dump_DemoThread2 = new Thread (new Java_lock_Dump_Demo_Sync_Thread(ob_b, ob_c ), "Java_lock_Dump_DemoThread2"); Thread Java_lock_Dump_DemoThread3 = new Thread (new Java_lock_Dump_Demo_Sync_Thread(ob_c, ob_a ), "Java_lock_Dump_DemoThread3"); Java_lock_Dump_DemoThread1.start(); Thread.sleep(3000); Java_lock_Dump_DemoThread2.start(); Thread.sleep(3000); Java_lock_Dump_DemoThread3.start(); } } class Java_lock_Dump_Demo_Sync_Thread implements Runnable { private Object ob_a; private Object ob_b; public Java_lock_Dump_Demo_Sync_Thread(Object ob_a, Object ob_b) { this.ob_a = ob_a; this.ob_b = ob_b; } @Override public void run() { String nm = Thread.currentThread().getName(); synchronized (ob_a) { System.out.println(nm + " acquire_the_lock_on_first_resource " + ob_a); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } synchronized (ob_b) { System.out.println(nm + " acquire_the_lock_on_second_resource " + ob_b); } System.out.println(nm + " Release_the_lock_for_second_object " + ob_b); } System.out.println(nm + " Release_the_lock_for_first_object " + ob_a); System.out.println(nm + " Completed with the deadlock_test for acquiring the resource."); } }
Output:
How to get the dump of the above-compiled code it can be done using the following commands :
Jcmd<Process_id> GC.heap_dump <file-path> jcmd 20528 GC.heap_dump C:\Users\adutta\eclipse-workspace\Matcher_Example\src
Java Dumps is considered a very interesting feature in java as It provides programmers and users with the ability to get out of the unwanted and unexpected situations at the time of halt in the running program as well as when the machine goes out of memory space. It also provides the user with detailed and proper content for the root cause or the troubleshooting issue.
The above is the detailed content of Java dumps. For more information, please follow other related articles on the PHP Chinese website!