Home > Java > javaTutorial > body text

What new methods are added to the Process API in Java 9?

WBOY
Release: 2023-09-09 10:49:02
forward
756 people have browsed it

在Java 9中,Process API新增了哪些新的方法?

Java 9 improves the Process class by adding new methods and also provides new interfaces: ProcessHandle and ProcessHandle .Info to get all the details about the process and its information.

The following is a list of new methods added to Process in Java 9

  • booleansupportsNormalTermination ():Returns true if executing destroy() terminates the process normally, Otherwise return false.
  • long pid():Can return the native process ID of the process.
  • ProcessHandle toHandle(): It can return the ProcessHandle of the process.
  • Streamchildren(): It can return a snapshot of the direct children of a process.
  • Streamdescendants(): It can return a snapshot of the descendants of a process.
  • ProcessHandle.Info info(): It can return a snapshot of information about the process.
  • CompletableFuture onExit(): It can return a CompletableFuture to terminate the process.

Example

public class ProcessTest {
   public static void main(String args[]) {
<strong>      ProcessHandle </strong>processHandle = ProcessHandle.current();
<strong>      ProcessHandle.Info</strong> processInfo = processHandle.info();
      System.out.println(processHandle.<strong>pid()</strong>);
      System.out.println(processHandle.<strong>parent()</strong>);
      System.out.println(processInfo.<strong>arguments()</strong>.<strong>isPresent()</strong>);
      System.out.println(processInfo.<strong>command()</strong>.<strong>isPresent()</strong>);
      System.out.println(processInfo.<strong>command().get().contains</strong>("tutorialspoint"));
      System.out.println(processInfo.<strong>startInstant().isPresent()</strong>);
   }
}
Copy after login

Output

<strong>4892
Optional[7788]
false
true
false
true</strong>
Copy after login

The above is the detailed content of What new methods are added to the 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