Computer >> Máy Tính >  >> Lập trình >> Java

Làm cách nào để có được ảnh chụp nhanh thông tin về API quy trình trong Java 9?


Java 9 đã cải thiện API quy trình bằng cách bao gồm các phương pháp mới và giới thiệu giao diện mới ProcessHandle ProcessHandle.Info để có được tất cả các chi tiết liên quan đến quy trình và thông tin của nó.

ProcessHandle giao diện có thể xác định và cung cấp quyền kiểm soát các quy trình gốc. Mỗi quá trình riêng lẻ có thể được theo dõi về độ sống , đã liệt kê các con của nó , nhận thông tin về quy trình hoặc tiêu hủy nó. ProcessHandle.Info giao diện cung cấp thông tin ảnh chụp nhanh về một quy trình.

Cú pháp

ProcessHandle.Info info()

Ví dụ

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());
   }
}

Đầu ra

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