Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Java JMX RuntimeMXBean

JMX Java 大约 2272 字

功能

RuntimeMXBean可以获取:

  • Pid: Java运行的进程号
  • StartTime: Java启动的时间
  • Uptime: Java当前运行了多久时间
  • Name: 获取当前Java运行在的主机名
  • InputArguments: 获取Java启动时的命令行参数
  • VmXXX: 获取Java虚拟机相关的信息

代码

public class RuntimeMXBeanTest {

    public static void main(String[] args) {
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        System.out.println("pid#" + runtimeMXBean.getPid());
        System.out.println("startTime#" + runtimeMXBean.getStartTime());
        System.out.println("uptime#" + runtimeMXBean.getUptime());
        System.out.println("name#" + runtimeMXBean.getName());
        System.out.println("classPath#" + runtimeMXBean.getClassPath());
        System.out.println("libraryPath#" + runtimeMXBean.getLibraryPath());
        System.out.println("inputArguments#" + runtimeMXBean.getInputArguments());
        System.out.println("managementSpecVersion#" + runtimeMXBean.getManagementSpecVersion());
        System.out.println("vmName#" + runtimeMXBean.getVmName());
        System.out.println("vmVendor#" + runtimeMXBean.getVmVendor());
        System.out.println("vmVersion#" + runtimeMXBean.getVmVersion());
        System.out.println("specName#" + runtimeMXBean.getSpecName());
        System.out.println("specVersion#" + runtimeMXBean.getSpecVersion());
        System.out.println("specVendor#" + runtimeMXBean.getSpecVendor());
        if (runtimeMXBean.isBootClassPathSupported()) {
            System.out.println("bootClassPath#" + runtimeMXBean.getBootClassPath());
        } else {
            System.out.println("bootClassPath not support");
        }
    }

}

输出

pid#61456
startTime#1704020195620
uptime#91
name#61456@fendoudebb
classPath#/Users/fendoudebb/github/quick-learn/java/target/production/quick-learn
libraryPath#/Users/fendoudebb/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
inputArguments#[-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=62957:/Applications/IntelliJ IDEA.app/Contents/bin, -Dfile.encoding=UTF-8]
managementSpecVersion#2.0
vmName#OpenJDK 64-Bit Server VM
vmVendor#Eclipse Adoptium
vmVersion#11.0.17+8
specName#Java Virtual Machine Specification
specVersion#11
specVendor#Oracle Corporation
bootClassPath not support
阅读 97 · 发布于 2023-12-31

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批