Java 轉儲是一些 Java 核心,當虛擬機器因網路問題、記憶體錯誤或使用者啟動任何類型的按鍵組合而意外停止時,這些核心會被錯誤建立。透過呼叫合併到應用程式原始程式碼中的 Java Dump API 或透過命令列直接提供 -Xdump:java 選項,可以輕鬆建立 Java Dump。 Java Dump 透過提供一些有用的信息來排除故障並診斷應用程式意外停止運行時發生的停止的根本原因,從而為最終用戶提供幫助。
開始您的免費軟體開發課程
網頁開發、程式語言、軟體測試及其他
文法
Java 轉儲沒有特定的語法,因為 Java 轉儲的需求取決於問題的根本原因,如前所述,問題的根本原因可能會有所不同。因此,此語法流程是當使用者需要診斷根本原因並希望使用jcmd 工具進行分析時,只需向JVM 發送所需的請求,並且必須在運行時使用與用於發送相同的系統這個請求發送給機器和Java程式。因此,語法定義如下:
jcmd <process_ id> GC.heap_dump <pathname_for_file>
傳遞的參數是:
Java 轉儲的工作流程非常有趣,因為它在機器崩潰或由於提到的各種原因(例如網路中斷、此外,任何形式的阻礙Java程式執行的錯誤都可以透過使用java Dumps來保存,以便進行故障排除和診斷根本原因。
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."); } }
輸出:
如何取得上述編譯程式碼的轉儲,可以使用以下指令來完成:
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.
以上是Java 轉儲的詳細內容。更多資訊請關注PHP中文網其他相關文章!