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

在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>);
   }
}

Output

<strong>4892
Optional[7788]
false
true
false
true</strong>

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!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
In Spring Boot Redis, how to solve the problem of returning garbled codes?In Spring Boot Redis, how to solve the problem of returning garbled codes?Apr 19, 2025 pm 07:36 PM

SpringBootRedis gets the key garbled problem analysis using Spring...

How to ensure consistency of output when using JSONObject and Map for data serialization?How to ensure consistency of output when using JSONObject and Map for data serialization?Apr 19, 2025 pm 07:33 PM

How to ensure consistency when using JSONObject and Map for data serialization? When processing JSON data, we may encounter using different methods for sequences...

How do Java regular expressions efficiently extract specific URLs in HTML text?How do Java regular expressions efficiently extract specific URLs in HTML text?Apr 19, 2025 pm 07:30 PM

Tips for extracting specific text by Java regular expressions In Java development, it is often necessary to extract the parts we are interested in from a large amount of text data. Regular...

In the development of the separate version of Ruoyi backend, why does the IDE report an error but does not affect the program execution?In the development of the separate version of Ruoyi backend, why does the IDE report an error but does not affect the program execution?Apr 19, 2025 pm 07:27 PM

Regarding the issue of obtaining front-end data from the Ruoyi version backend When using the Ruoyi version development project, you often encounter the problem of obtaining data from the front-end and entering the back-end...

How to dynamically configure entity class annotation parameters using easypoi.excel library in Java to suit different environments?How to dynamically configure entity class annotation parameters using easypoi.excel library in Java to suit different environments?Apr 19, 2025 pm 07:24 PM

How to dynamically configure entity class annotation parameters in Java? In Java development, we often encounter the need to dynamically configure certain parameters according to different environments...

Why does the browser fail to correctly process the 401 status code when developing a WebSocket server using Netty?Why does the browser fail to correctly process the 401 status code when developing a WebSocket server using Netty?Apr 19, 2025 pm 07:21 PM

在使用Netty开发WebSocket服务器时,可能会遇到浏览器在尝试连接时未能正确处理服务器返回的401状态码的情况。 �...

Java compilation failed: What should I do if the javac command cannot generate the class file?Java compilation failed: What should I do if the javac command cannot generate the class file?Apr 19, 2025 pm 07:18 PM

Java compilation failed: Running window javac command cannot generate class file Many Java beginners will encounter this problem during the learning process: running window...

How to correctly divide business logic and non-business logic in hierarchical architecture in back-end development?How to correctly divide business logic and non-business logic in hierarchical architecture in back-end development?Apr 19, 2025 pm 07:15 PM

Discussing the hierarchical architecture problem in back-end development. In back-end development, common hierarchical architectures include controller, service and dao...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.