Java 執行時 traceInstructions() 方法



描述

Java 執行時 traceInstructions(boolean on) 方法啟用/停用指令跟蹤。如果布林型引數為 true,則此方法表示 Java 虛擬機器在執行虛擬機器中的每個指令時發出除錯資訊。此資訊格式以及其輸出到的檔案或其他輸出流取決於主機環境。如果虛擬機器不支援此功能,則可能會忽略此請求。跟蹤輸出的目標取決於系統。如果布林型引數為 false,則此方法會導致虛擬機器停止執行其正在執行的詳細指令跟蹤。

宣告

以下是 java.lang.Runtime.traceInstructions() 方法的宣告

public void traceInstructions(boolean on)

引數

on - true 表示啟用指令跟蹤;false 表示停用此功能。

返回值

此方法不返回值。

異常

示例:啟用指令跟蹤

以下示例演示了 Java Runtime traceInstructions() 方法的使用。我們使用 traceInstructions(true) 方法啟用了當前 JVM 的指令跟蹤。

package com.tutorialspoint;

public class RuntimeDemo {

   public static void main(String[] args) {

      // print the state of the program
      System.out.println("Program is starting...");

      // start tracing for instructions
      System.out.println("Enabling tracing...");
      Runtime.getRuntime().traceInstructions(true);
      System.out.println("Done!");
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Program is starting...
Enabling tracing...
Done!

示例:停用指令跟蹤

以下示例演示了 Java Runtime traceInstructions() 方法的使用。我們使用 traceInstructions(false) 方法停用了當前 JVM 的指令跟蹤。

package com.tutorialspoint;

public class RuntimeDemo {

   public static void main(String[] args) {

      // print the state of the program
      System.out.println("Program is starting...");

      // start tracing for instructions
      System.out.println("Disabling tracing...");
      Runtime.getRuntime().traceInstructions(false);
      System.out.println("Done!");
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Program is starting...
Disabling tracing...
Done!
java_lang_runtime.htm
廣告

© . All rights reserved.