mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
fix code
This commit is contained in:
parent
2d72e54deb
commit
4ebec434a1
@ -461,7 +461,8 @@ public class NetUtil {
|
||||
* 如果获取失败调用 {@link InetAddress#getLocalHost()}方法获取。<br>
|
||||
* 此方法不会抛出异常,获取失败将返回{@code null}<br>
|
||||
* <p>
|
||||
* 参考:http://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java
|
||||
* 参考:<a href="http://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java">
|
||||
* http://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java</a>
|
||||
*
|
||||
* @return 本机网卡IP地址,获取失败返回{@code null}
|
||||
* @since 3.0.7
|
||||
@ -484,7 +485,7 @@ public class NetUtil {
|
||||
* <p>
|
||||
* 此方法不会抛出异常,获取失败将返回{@code null}<br>
|
||||
* <p>
|
||||
* 见:https://github.com/dromara/hutool/issues/428
|
||||
* 见:<a href="https://github.com/dromara/hutool/issues/428">https://github.com/dromara/hutool/issues/428</a>
|
||||
*
|
||||
* @return 本机网卡IP地址,获取失败返回{@code null}
|
||||
* @since 3.0.1
|
||||
|
@ -0,0 +1,37 @@
|
||||
package cn.hutool.extra.management;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* FtpException异常
|
||||
*
|
||||
* @author xiaoleilu
|
||||
*/
|
||||
public class ManagementException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ManagementException(final Throwable e) {
|
||||
super(ExceptionUtil.getMessage(e), e);
|
||||
}
|
||||
|
||||
public ManagementException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ManagementException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
}
|
||||
|
||||
public ManagementException(final String message, final Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
|
||||
public ManagementException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, throwable, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ManagementException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Singleton;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.management.ClassLoadingMXBean;
|
||||
import java.lang.management.CompilationMXBean;
|
||||
@ -18,8 +20,11 @@ import java.lang.management.ThreadMXBean;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Java的System类封装工具类。<br>
|
||||
* 参考:<a href="http://blog.csdn.net/zhongweijian/article/details/7619383">http://blog.csdn.net/zhongweijian/article/details/7619383</a>
|
||||
* Java的JMX(Java Management Extensions)相关封装工具类。<br>
|
||||
* JMX就是Java管理扩展,用来管理和监测 Java 程序。最常用到的就是对于 JVM 的监测和管理,比如 JVM 内存、CPU 使用率、线程数、垃圾收集情况等等。<br>
|
||||
* 参考:
|
||||
* <a href="http://blog.csdn.net/zhongweijian/article/details/7619383">http://blog.csdn.net/zhongweijian/article/details/7619383</a><br>
|
||||
* <a href="https://zhuanlan.zhihu.com/p/166530442">https://zhuanlan.zhihu.com/p/166530442</a>
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
@ -246,6 +251,32 @@ public class ManagementUtil {
|
||||
return ManagementFactory.getGarbageCollectorMXBeans();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@link MBeanServer}<br>
|
||||
* MBeanServer是负责管理MBean的,一般一个JVM只有一个MBeanServer,所有的MBean都要注册到MBeanServer上,并通过 MBeanServer 对外提供服务。
|
||||
*
|
||||
* @return {@link MBeanServer}
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static MBeanServer getMBeanServer() {
|
||||
return ManagementFactory.getPlatformMBeanServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册MBean
|
||||
*
|
||||
* @param mBean Mbean对象
|
||||
* @param name MBean 的唯一标示
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static void registerMBean(final Object mBean, final ObjectName name) {
|
||||
try {
|
||||
getMBeanServer().registerMBean(mBean, name);
|
||||
} catch (final Exception e) {
|
||||
throw new ManagementException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得Java Virtual Machine Specification的信息。
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user