jmx的ObjectName中key对应的value的获取
程序员文章站
2024-02-18 12:15:58
...
之前开发中用到JMX的地方,如果需要根据ObjectName中某个特定值进行判断,都是把ObjectName执行toString()后,再截取字符串,今天发现原来ObjectName中有个方法
该方法只要把相应的key传进来就可以获取值,而不用再在整个String中查找。
比如
:wink:
/**
* 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: