Class ModernProcessIdResolver

  • All Implemented Interfaces:
    Prioritized, ProcessIdResolver, java.lang.Comparable<Prioritized>

    public class ModernProcessIdResolver
    extends java.lang.Object
    implements ProcessIdResolver
    A ProcessIdResolver implementation for modern JDKs (Java 9+).

    This class uses the java.lang.ProcessHandle API introduced in Java 9 to retrieve the current process ID. It dynamically checks for the presence of the required classes and methods at runtime, ensuring compatibility with different JDK versions.

    Example Usage

    
     ProcessIdResolver resolver = new ModernProcessIdResolver();
     if (resolver.supports()) {
         Long pid = resolver.current();
         System.out.println("Current Process ID: " + pid);
     } else {
         System.out.println("Process ID resolution not supported on this JVM version.");
     }
     
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    ProcessIdResolver, java.lang.ProcessHandle
    • Constructor Detail

      • ModernProcessIdResolver

        public ModernProcessIdResolver()
    • Method Detail

      • supports

        public boolean supports()
        Description copied from interface: ProcessIdResolver
        Whether supports to resolve the process id or not?
        Specified by:
        supports in interface ProcessIdResolver
        Returns:
        true if supports, otherwise false
      • current

        public java.lang.Long current()
        Description copied from interface: ProcessIdResolver
        Resolve the current process id
        Specified by:
        current in interface ProcessIdResolver
        Returns:
        >null if can't be resolved