ITeye博客

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

chainhou · 2013-07-11 14:12 · 编程语言 · Markdown

之前开发中用到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)

暂无评论。

评论功能维护中,当前仅展示历史评论。