public static long readLongAttribute(String attributeName, long defaultValue) {
        try {
            String methodName = "get" + attributeName;
            OperatingSystemMXBean systemMXBean = OPERATING_SYSTEM_MX_BEAN;
            Method method = systemMXBean.getClass().getMethod(methodName);
            method.setAccessible(true);

            Object value = method.invoke(systemMXBean);
            if (value == null) {
                return defaultValue;
            }

            if (value instanceof Long) {
                return (Long) value;
            }

            if (value instanceof Double) {
                double v = (Double) value;
                return Math.round(v * PERCENTAGE_MULTIPLIER);
            }

            if (value instanceof Number) {
                return ((Number) value).longValue();
            }

        } catch (RuntimeException re) {
            throw re;
        } catch (Exception ignored) {
            ignore(ignored);
        }
        return defaultValue;
    }
public static long readLongAttribute ( String attributeName , long defaultValue ) { try { String methodName = "get" + attributeName ; OperatingSystemMXBean systemMXBean = OPERATING_SYSTEM_MX_BEAN ; Method method = systemMXBean . getClass ( ) . getMethod ( methodName ) ; method . setAccessible ( true ) ; Object value = method . invoke ( systemMXBean ) ; if ( value == null ) { return defaultValue ; } if ( value instanceof Long ) { return ( Long ) value ; } if ( value instanceof Double ) { double v = ( Double ) value ; return Math . round ( v * PERCENTAGE_MULTIPLIER ) ; } if ( value instanceof Number ) { return ( ( Number ) value ) . longValue ( ) ; } } catch ( RuntimeException re ) { throw re ; } catch ( Exception ignored ) { ignore ( ignored ) ; } return defaultValue ; }
Reads a long attribute from OperatingSystemMXBean.

@param attributeName name of the attribute
@param defaultValue  default value if the attribute value is null
@return value of the attribute