jvm系统参数获取

获取jvm相关系统参数

import com.sun.management.OperatingSystemMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLDecoder;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;

public class LocalJvmInfoPicker implements JvmInfoPicker {
    private static final String QUOTATION = "\"";
    private static final String COLON = ":";
    private static final String COMMA = ",";
    private long uptime;
    private long processCpuTime;
    private GarbageCollectorMXBean youngGC;
    private GarbageCollectorMXBean fullGC;
    private static LocalJvmInfoPicker instance = new LocalJvmInfoPicker();

    private LocalJvmInfoPicker() {
        List<GarbageCollectorMXBean> gcList = ManagementFactory.getGarbageCollectorMXBeans();
        if (gcList != null && !gcList.isEmpty()) {
            if (gcList.size() == 1) {
                this.youngGC = (GarbageCollectorMXBean)gcList.get(0);
            } else if (gcList.size() >= 2) {
                this.youngGC = (GarbageCollectorMXBean)gcList.get(0);
                this.fullGC = (GarbageCollectorMXBean)gcList.get(1);
            }

        }
    }

    public static LocalJvmInfoPicker getInstance() {
        return instance;
    }

    public static String getYoungGCName() {
        return instance.youngGC != null ? instance.youngGC.getName() : "NULL";
    }

    public static String getFullGCName() {
        return instance.fullGC != null ? instance.fullGC.getName() : "NULL";
    }

    public static String getYoungGCTime() {
        return instance.youngGC != null ? String.valueOf(instance.youngGC.getCollectionTime()) : "0";
    }

    public static String getYoungGCCount() {
        return instance.youngGC != null ? String.valueOf(instance.youngGC.getCollectionCount()) : "0";
    }

    public static String getFullGCTime() {
        return instance.fullGC != null ? String.valueOf(instance.fullGC.getCollectionTime()) : "0";
    }

    public static String getFullGCCount() {
        return instance.fullGC != null ? String.valueOf(instance.fullGC.getCollectionCount()) : "0";
    }

    public static long getFullGCStartTime() {
        return 0L;
    }

    public static long getFullGCEndTime() {
        return 0L;
    }

    public static long getYoungGCStartTime() {
        return 0L;
    }

    public static long getYoungGCEndTime() {
        return 0L;
    }

    public static long getYoungGCDuration() {
        return 0L;
    }

    public static long getFullGCDuration() {
        return 0L;
    }

    public String getOSArch() {
        return System.getProperties().getProperty("os.arch");
    }

    public String getOSName() {
        return System.getProperties().getProperty("os.name");
    }

    public String getSystemModel() {
        return System.getProperties().getProperty("sun.arch.data.model");
    }

    public String getLibPath() {
        return System.getProperties().getProperty("java.library.path");
    }

    public String getJREVersion() {
        return System.getProperties().getProperty("java.version");
    }

    public String getStartTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return sdf.format(ManagementFactory.getRuntimeMXBean().getStartTime());
    }

    public String getClassPath() {
        return ManagementFactory.getRuntimeMXBean().getClassPath();
    }

    public String getBootClassPath() {
        return ManagementFactory.getRuntimeMXBean().getBootClassPath();
    }

    public long getPeakThreadCount() {
        return (long)ManagementFactory.getThreadMXBean().getPeakThreadCount();
    }

    public long getThreadCount() {
        return (long)ManagementFactory.getThreadMXBean().getThreadCount();
    }

    public 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值