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

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

WBOY
发布: 2023-08-19 18:17:09
转载
964 人浏览过

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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板