Interface ProcessChecker


public interface ProcessChecker
Interface for checking if a process (typically the parent Maven plugin) is still alive.

Implementations allow the forked JVM to detect when its parent Maven process has terminated, enabling cleanup and preventing orphaned processes.

Since:
3.5.5
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Deprecated.
    with using ProcessHandleChecker on Java 9+, this method will always return true and can be removed in a future release.
    void
    Destroys any active commands or subprocesses used by this checker.
    boolean
    Checks if the process is still alive.
    static boolean
    Returns whether the ProcessHandle API is available in the current JVM.
    boolean
    Checks if the checker has been stopped.
    of(String ppid)
    Creates the appropriate ProcessChecker implementation for the given parent PID.
    org.apache.maven.surefire.booter.ProcessInfo
    Returns information about the process being checked.
    void
    Stops the checker and releases any resources.
  • Method Details

    • of

      static ProcessChecker of(String ppid)
      Creates the appropriate ProcessChecker implementation for the given parent PID.

      On Java 9+, uses ProcessHandleChecker which leverages the ProcessHandle API. On Java 8, falls back to PpidChecker which uses native commands.

      Parameters:
      ppid - the parent process ID as a string, or null
      Returns:
      a new checker instance, or null if ppid is null
    • isProcessHandleSupported

      static boolean isProcessHandleSupported()
      Returns whether the ProcessHandle API is available in the current JVM.
      Returns:
      true if running on Java 9+ with ProcessHandle available
    • canUse

      @Deprecated boolean canUse()
      Deprecated.
      with using ProcessHandleChecker on Java 9+, this method will always return true and can be removed in a future release.
      Checks whether this checker can be used to monitor the process.

      This method must return true before isProcessAlive() can be called.

      Returns:
      true if the checker is operational and can monitor the process
    • isProcessAlive

      boolean isProcessAlive()
      Checks if the process is still alive.

      This method can only be called after canUse() has returned true.

      Returns:
      true if the process is still running; false if it has terminated or if the PID has been reused by a different process
      Throws:
      IllegalStateException - if canUse() returns false or if the checker has been stopped
    • stop

      void stop()
      Stops the checker and releases any resources.

      After calling this method, canUse() will return false.

    • destroyActiveCommands

      void destroyActiveCommands()
      Destroys any active commands or subprocesses used by this checker.

      This is called during shutdown to ensure clean termination.

    • isStopped

      boolean isStopped()
      Checks if the checker has been stopped.
      Returns:
      true if stop() or destroyActiveCommands() has been called
    • processInfo

      org.apache.maven.surefire.booter.ProcessInfo processInfo()
      Returns information about the process being checked.
      Returns:
      the process information, or null if not yet initialized