Di Java 9, seseorang boleh mendapatkan semula PID proses melalui panggilan asli dan boleh dicapai melalui ProcessHandle. Kami juga boleh mendapatkan maklumat tentang Java Process (JVM) dan Info (kelas dalaman bagi ProcessHandle) yang sedang dijalankan yang mengandungi butiran tentang proses tersebut. Kami juga boleh mengembalikan snapshot semua proses yang sedang berjalan dalam sistem.
import java.lang.ProcessHandle.Info; public class ProcessAPIChanges { public void detailedAPIInfo(<strong>ProcessHandle </strong>processHandle) { <strong>Info </strong>processInfo = processHandle.<strong>info()</strong>; System.out.println("Detailed Process Info is Provided Below: "); System.out.println("[Executable Name] " + processInfo.<strong>command().get()</strong>); System.out.println("[User Name] " + processInfo.<strong>user().get()</strong>); System.out.println("[Start Time] " + processInfo.<strong>startInstant().get().toString()</strong>); } public static void main(String args[]) { System.out.println("Process API Changes (Core Library) "); ProcessAPIChanges processAPIChanges = new ProcessAPIChanges(); <strong>ProcessHandle </strong>processHandle = ProcessHandle.<strong>current()</strong>; System.out.println("[Current Process Id] " + processHandle.<strong>pid()</strong>); processAPIChanges.detailedAPIInfo(processHandle); ProcessHandle.allProcesses() .<strong>filter</strong>(ph -> ph.info().command().<strong>isPresent()</strong>) .<strong>limit</strong>(4).forEach((process) -> processAPIChanges.detailedAPIInfo(process)); } }
<strong>Process API Changes (Core Library) [Current Process Id] 5724 Detailed Process Info is Provided Below: [Executable Name] C:\Program Files\Java\jdk-9.0.4\bin\java.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T07:35:43.152Z Detailed Process Info is Provided Below: [Executable Name] C:\WINDOWS\System32\taskhostex.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:36.241Z Detailed Process Info is Provided Below: [Executable Name] C:\Program Files\Synaptics\SynTP\SynTPEnh.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:36.257Z Detailed Process Info is Provided Below: [Executable Name] C:\WINDOWS\explorer.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:36.335Z Detailed Process Info is Provided Below: [Executable Name] C:\Program Files (x86)\Dell Wireless\Bluetooth Suite\BtvStack.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:51.594Z</strong>
Atas ialah kandungan terperinci Apakah perubahan perpustakaan teras kepada API Proses dalam Java 9?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!