Package io.microsphere.process
Class ModernProcessIdResolver
- java.lang.Object
-
- io.microsphere.process.ModernProcessIdResolver
-
- All Implemented Interfaces:
Prioritized,ProcessIdResolver,java.lang.Comparable<Prioritized>
public class ModernProcessIdResolver extends java.lang.Object implements ProcessIdResolver
AProcessIdResolverimplementation for modern JDKs (Java 9+).This class uses the
java.lang.ProcessHandleAPI 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
-
-
Field Summary
-
Fields inherited from interface io.microsphere.lang.Prioritized
COMPARATOR, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY
-
Fields inherited from interface io.microsphere.process.ProcessIdResolver
UNKNOWN_PROCESS_ID
-
-
Constructor Summary
Constructors Constructor Description ModernProcessIdResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Longcurrent()Resolve the current process idintgetPriority()Get the prioritybooleansupports()Whether supports to resolve the process id or not?-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.microsphere.lang.Prioritized
compareTo
-
-
-
-
Method Detail
-
supports
public boolean supports()
Description copied from interface:ProcessIdResolverWhether supports to resolve the process id or not?- Specified by:
supportsin interfaceProcessIdResolver- Returns:
trueif supports, otherwisefalse
-
current
public java.lang.Long current()
Description copied from interface:ProcessIdResolverResolve the current process id- Specified by:
currentin interfaceProcessIdResolver- Returns:
>nullif can't be resolved
-
getPriority
public int getPriority()
Description copied from interface:PrioritizedGet the priority- Specified by:
getPriorityin interfacePrioritized- Returns:
- the default is
minimum one
-
-