首頁 > Java > java教程 > 主體

Java 9中進程API的核心庫變化是什麼?

WBOY
發布: 2023-08-19 18:17:09
轉載
904 人瀏覽過

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

在 Java 9 中,可以透過本機呼叫檢索進程的 PID ,並且可以透過 ProcessHandle 來實現。我們還可以檢索有關當前正在運行的Java 進程(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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!