Class ProcessApiExamples

java.lang.Object
net.jrodolfo.java_evolution.java09.ProcessApiExamples

public class ProcessApiExamples extends Object
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.

  • 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

      public Optional<String> currentProcessCommand()
      Reads the current process command when the JVM can provide it.
      Returns:
      an Optional containing the command path or name
    • parentProcess

      public Optional<ProcessHandle> parentProcess()
      Reads the parent process when one is visible to the JVM.
      Returns:
      the parent process handle, or an empty Optional
    • currentProcessSummary

      public ProcessApiExamples.CurrentProcessSummary currentProcessSummary()
      Creates a small immutable summary of the current process.
      Returns:
      process metadata that can be asserted in tests