Skip to content

io microsphere process VirtualMachineProcessIdResolver

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

VirtualMachineProcessIdResolver

Type: Class | Module: microsphere-java-core | Package: io.microsphere.process | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/process/VirtualMachineProcessIdResolver.java

Overview

A ProcessIdResolver implementation for retrieving the process ID using the SUN JVM internal APIs.

This resolver utilizes reflection to access the internal fields and methods of the JVM, specifically targeting the sun.management.VMManagementImpl class which provides a method to retrieve the native process ID.

How It Works

The process ID is obtained via reflection by accessing the hidden "jvm" field in the RuntimeMXBean instance, and then invoking the getProcessId() method on that internal object. This approach is specific to the HotSpot JVM and may not be available on all JVM implementations.

Example Usage

`ProcessIdResolver resolver = new VirtualMachineProcessIdResolver();
if (resolver.supports()) {
    Long pid = resolver.current();
    System.out.println("Current Process ID: " + pid);
`
}

Priority

This resolver has a priority level of #getPriority(), making it preferred over some other resolvers but not the highest priority. The priority helps determine which resolver should be used when multiple resolvers are available.

Declaration

public class VirtualMachineProcessIdResolver implements ProcessIdResolver

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

ProcessIdResolver resolver = new VirtualMachineProcessIdResolver();
if (resolver.supports()) {
    Long pid = resolver.current();
    System.out.println("Current Process ID: " + pid);
}

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.process.VirtualMachineProcessIdResolver;

API Reference

Public Methods

Method Description
supports
current
getPriority

See Also

  • ProcessIdResolver

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally