首页 > Java > java教程 > 正文

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

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

java 9中进程api的核心库变化是什么?

百度文心百中
百度文心百中

百度大模型语义搜索体验中心

百度文心百中 22
查看详情 百度文心百中

In Java 9, one can retrieve the PID of the process through a native call and can be achievable through the ProcessHandle. We can also retrieve information about the currently running Java Process (JVM) and Info (inner class of ProcessHandle) class that contains details about the process. We can also return a snapshot of all currently running processes in the system.

Example

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中文网其它相关文章!

相关标签:
java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号