Class ManagementUtils

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getCurrentProcessId()
      Get the process ID of current JVM
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getCurrentProcessId

        public static long getCurrentProcessId()
        Get the process ID of current JVM

        Example Usage

        
         // Get the current process ID
         long pid = ManagementUtils.getCurrentProcessId();
         if (pid != -1) {
             System.out.println("Current Process ID: " + pid);
         } else {
             System.out.println("Failed to resolve process ID.");
         }
         

        This class uses the ServiceLoader pattern to discover and load all available implementations of ProcessIdResolver, and selects the most appropriate one based on support and priority. If no resolver can determine the process ID, it defaults to ProcessIdResolver.UNKNOWN_PROCESS_ID.

        Returns:
        If can't get the process ID , return -1