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!

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

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

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...

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 in Java? In Java development, we often encounter the need to dynamically configure certain parameters according to different environments...

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

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

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.