jmx的ObjectName中key对应的value的获取

之前开发中用到JMX的地方,如果需要根据ObjectName中某个特定值进行判断,都是把ObjectName执行toString()后,再截取字符串,今天发现原来ObjectName中有个方法

/**
* Obtains the value associated with a key in a key property.
*
* @param property The property whose value is to be obtained.
*
* @return The value of the property, or null if there is no such
* property in this ObjectName.
*
* @exception NullPointerException If <code>property</code> is null.
*/
public String getKeyProperty(String property) throws NullPointerException {
return _getKeyPropertyList().get(property);
}

该方法只要把相应的key传进来就可以获取值,而不用再在整个String中查找。
比如

ObjectName oname = new ObjectName("com.abc:name=threadpool.thread-pool-1,type=thread-pool,category=monitor,server=server");
要获取name的值,只需要oname.getKeyProperty("name");即可把后面的一串拿到。

:wink:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值