Class ProcessApiExamples
java.lang.Object
net.jrodolfo.java_evolution.java09.ProcessApiExamples
Demonstrates Process API updates introduced in Java 9.
Before Java 9, Java had limited standard APIs for process metadata. Code that needed a process id, parent process, or command information often had to call platform-specific shell commands or native code.
ProcessHandle solves this by giving Java code a standard way to
inspect the current process and related process metadata without launching
platform-specific commands.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSmall Java 9-style data class for process metadata. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReads the current process command when the JVM can provide it.longReads the current process id.Creates a small immutable summary of the current process.Reads the parent process when one is visible to the JVM.
-
Constructor Details
-
ProcessApiExamples
public ProcessApiExamples()
-
-
Method Details
-
currentProcessId
public long currentProcessId()Reads the current process id.- Returns:
- the id of the JVM process running this code
-
currentProcessCommand
-
parentProcess
Reads the parent process when one is visible to the JVM.- Returns:
- the parent process handle, or an empty Optional
-
currentProcessSummary
Creates a small immutable summary of the current process.- Returns:
- process metadata that can be asserted in tests
-