首页  >  文章  >  Java  >  Java 9中进程API的核心库变化是什么?

Java 9中进程API的核心库变化是什么?

WBOY
WBOY转载
2023-08-19 18:17:09911浏览

Java 9中进程API的核心库变化是什么?

在 Java 9 中,可以通过本机调用检索进程的PID,并且可以通过ProcessHandle实现。我们还可以检索有关当前运行的 Java Process (JVM) 和 Info ProcessHandle的内部类)类的信息,其中包含有关进程的详细信息。我们还可以返回系统中所有当前正在运行的进程的快照

示例

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>

以上是Java 9中进程API的核心库变化是什么?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除