Skip to content

io microsphere process ClassicProcessIdResolver

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

ClassicProcessIdResolver

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

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

Overview

A ProcessIdResolver implementation for classic JDK versions (5 - 8).

This class resolves the current process ID using the name obtained from java.lang.management.RuntimeMXBean#getName(). The format of the returned name is usually:

- `pid@hostname`

where pid represents the process ID. This resolver extracts and returns the numeric part before the '@' symbol.

Supported Environments

This resolver is designed to work on Java 5 through Java 8, where newer APIs like java.lang.ProcessHandle#current() are not available.

Example Output

`// Assuming RuntimeMXBean.getName() returns "12345@localhost"
ClassicProcessIdResolver resolver = new ClassicProcessIdResolver();
if (resolver.supports()) {
    Long pid = resolver.current();
    System.out.println("Current PID: " + pid); // Outputs: Current PID: 12345
`
}

Logging Behavior

If trace logging is enabled via the underlying logger (io.microsphere.logging.Logger), this resolver logs the resolved PID along with the raw value obtained from the runtime MXBean:

`[TRACE] The PID was resolved from the method 'java.lang.management.RuntimeMXBean#getName()' = 12345@localhost : 12345
`

Priority

This resolver has a priority level set to Prioritized#NORMAL_PRIORITY plus 9, which means it will be considered after resolvers with higher priority but before those with lower.

Declaration

public class ClassicProcessIdResolver 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

Example 1

// Assuming RuntimeMXBean.getName() returns "12345@localhost"
ClassicProcessIdResolver resolver = new ClassicProcessIdResolver();
if (resolver.supports()) {
    Long pid = resolver.current();
    System.out.println("Current PID: " + pid); // Outputs: Current PID: 12345
}

Example 2

[TRACE] The PID was resolved from the method 'java.lang.management.RuntimeMXBean#getName()' = 12345@localhost : 12345

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.ClassicProcessIdResolver;

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