Java 9 cải tiến Process API bằng phương thức mới và giới thiệu interface ProcessHandle và ProcessHandle.Info để lấy chi tiết tiến trình và thông tin của nó.
Interface ProcessHandle xác định và kiểm soát tiến trình native. Mỗi tiến trình riêng lẻ có thể giám sát sự sống, liệt kê tiến trình con, lấy thông tin tiến trình hoặc hủy nó. Interface ProcessHandle.Info cung cấp ảnh chụp thông tin snapshot về tiến trình.
Cú pháp
ProcessHandle.Info info()
Ví dụ
public class ProcessSnapShotTest {
public static void main(String[] args) {
ProcessHandle currentProcessHandleImpl = ProcessHandle.current();
// Ảnh chụp tiến trình hiện tại với ProcessHandle.Info:
ProcessHandle.Info processInfo = currentProcessHandleImpl.info();
System.out.println("Ảnh chụp tiến trình đang chạy:");
System.out.println("User : " + processInfo.user().get());
System.out.println("Start Time : " + processInfo.startInstant().get());
}
}
Kết quả
Ảnh chụp tiến trình đang chạy: User : Tutorialspoint\User Start Time : 2020-05-01T05:44:41.458Z