This knolx explains the concept of process API Updates in Java 9. It covers the following topics :
1. Process
2. Process Builder
3. Process Handler
4. Process Handler Info
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
Java9 - Part II
1. Java 9 - Part II
Jasmine Kaur
Software Consultant (Knoldus)
2. Agenda: Process API Updates
● Process
● Process Builder
● Process Handler
● Process Handler Info
3. New features which came in Java
9● JPMS ( Java Platform Modular System)
● Jshell
● Jlink
● Http2/Client
● ...
● Process API Updates
4. Process API Updates
● Process id of current running process
● Create a new process (Example : open a notepad, compile a java
program)
● Destroy already running process (Example : Close a notepad, stop a
java program)
● Get complete information of a process
● Get child process information
● Get parent process information
5. What’s new in Java 9 Process API ?
● Process class : Several new methods were added like pid(), info() etc
● ProcessBuilder : Use to create our own operating system process
● ProcessHandle interface : Use to handle the processes like access current
running process, access the parent/child of a particular process
● ProcessHandle.Info : Inner interface inside ProcessHandle interface. It is use
to provide the complete information of a current running process.
Note: All these classes and interfaces are present inside java.lang package, so we are
not required to use any import statements.
6. How to get ProcessHandle Object
1. ProcessHandle handle = ProcessHandle.current();
2. ProcessHandle handle = process.toHandle();
// where process is the Process object
3. Optional<ProcessHandle> handle = ProcessHandle.of(PID);
8. ProcessBuilder
This class is used to make the operating system processes.
ProcessBuilder processBuilder = new ProcessBuilder(String... command);
Process process = processBuilder.start();
Note : The argument should be a valid command to invoke the process.
9. Creation and destroying a process
● Create and destroy process from java using
ProcessBuilder.
● Destroy a project which is not created from java.