Home > Java > javaTutorial > What are the improvements to Process API in Java 9?

What are the improvements to Process API in Java 9?

WBOY
Release: 2023-08-20 22:37:34
forward
850 people have browsed it

在Java 9中,Process API有哪些改进?

Java has improved the Process API in the Java 9 version, which can help manage and control operating system processes. In earlier versions, it was difficult to manage and control operating system processes using Java. Now, in Java 9 new classes and interfaces have been added to perform this task. ProcessHandle The interface is used to identify and control the local process, and provides methods to check process survivability and destroy the process. ProcessHandle.Info The interface provides an information snapshot of the process.

Process API Provides more information, such as:

  • The native process ID of the process
  • Cumulative CPU time
  • Parent process
  • Methods to destroy a process
  • Descendants of a process, etc.

Example

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>);
   }
}
Copy after login

Output

<strong>PID: 6004
totalCpuDuration: Optional[PT0.421875S]
user: Optional[Tutorialspoint\User]</strong>
Copy after login

The above is the detailed content of What are the improvements to Process API in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template