Get the ObjectName jmx key value corresponding to

After previously used in the development of local JMX, if need be judged in accordance with a specific value ObjectName, ObjectName is the implementation of toString (), and then the interception of the string, and today found that there is a method in 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);
}

The method as long as the corresponding key-entered value you can get, but do not have to look at the entire String.
such as

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

:wink:
Published 56 original articles · won praise 0 · Views 7777

Guess you like

Origin blog.csdn.net/chainhou/article/details/84457716