All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hibegin.common.util.Pid Maven / Gradle / Ivy

Go to download

Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project. Can quickly run embedded, Android devices

There is a newer version: 0.3.162
Show newest version
package com.hibegin.common.util;

import java.lang.reflect.Method;
import java.util.logging.Logger;

public class Pid {

    public static final Logger LOGGER = LoggerUtil.getLogger(Pid.class);

    public static long get() {
        try {
            //兼容java7
            if (Class.forName("java.lang.management.ManagementFactory") != null) {
                Object runtimeMXBean = Class.forName("java.lang.management.ManagementFactory").getMethod("getRuntimeMXBean").invoke(null);
                Method method = runtimeMXBean.getClass().getMethod("getName");
                method.setAccessible(true);
                return Long.parseLong(((String) method.invoke(runtimeMXBean)).split("@")[0]);
            }
        } catch (Exception e) {
            LOGGER.warning("get pid error " + e.getMessage());
        }
        return -1;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy