Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Java

จะรับสแน็ปช็อตข้อมูลเกี่ยวกับ Process API ใน Java 9 ได้อย่างไร


Java 9 ได้ปรับปรุง Process API โดยการรวมวิธีการใหม่และแนะนำอินเทอร์เฟซใหม่ ProcessHandle และ ProcessHandle.Info เพื่อรับรายละเอียดทั้งหมดเกี่ยวกับกระบวนการและข้อมูล

ตัวจัดการกระบวนการ อินเทอร์เฟซสามารถระบุและให้การควบคุมกระบวนการดั้งเดิม แต่ละกระบวนการสามารถตรวจสอบความมีชีวิตชีวา , แสดงรายการ ลูก รับข้อมูลเกี่ยวกับกระบวนการ หรือ ทำลาย มัน. ProcessHandle.Info อินเทอร์เฟซให้ข้อมูล ภาพรวม เกี่ยวกับกระบวนการ

ไวยากรณ์

ProcessHandle.Info info()

ตัวอย่าง

public class ProcessSnapShotTest {
   public static void main(String[] args) {
      ProcessHandle currentProcessHandleImpl = ProcessHandle.current();
      
      // Process snapshot of the current running process with ProcessHandle.Info:
      ProcessHandle.Info processInfo = currentProcessHandleImpl.info();

      System.out.println("nProcess snapshot of the current running process:");
      System.out.println("User : " + processInfo.user().get());
      System.out.println("Start Time : " + processInfo.startInstant().get());
   }
}

ผลลัพธ์

Process snapshot of the current running process:
User : Tutorialspoint\User
Start Time : 2020-05-01T05:44:41.458Z