在Java 9中,Process API有哪些改进?
Process API 提供了更多的信息,例如:
- 进程的本机进程 ID
- 累积 CPU 时间
- 父进程
- 销毁进程的方法
- 进程的后代等
示例
public class ProcessTest { public static void main(String args[]) { <strong>ProcessHandle </strong>currentProcess = ProcessHandle.current(); System.out.println("PID: " + currentProcess.<strong>pid()</strong>); <strong>ProcessHandle.Info</strong> currentProcessInfo = currentProcess.<strong>info()</strong>; System.out.println("totalCpuDuration: " + currentProcessInfo.<strong>totalCpuDuration()</strong>); System.out.println("user: " + currentProcessInfo.<strong>user()</strong>); } }
输出
<strong>PID: 6004 totalCpuDuration: Optional[PT0.421875S] user: Optional[Tutorialspoint\User]</strong>
以上就是在Java 9中,Process API有哪些改进?的详细内容,更多请关注其它相关文章!