【发布时间】:2012-02-07 14:08:58
【问题描述】:
我正在尝试使用 MBean 获取jboss-service.xml 中绑定的服务类的实例。
JBoss-Service.xml 定义了一个BasicThreadPool,我们想在我们的代码中使用它。
这就是JBOSS-Service.xml 中的内容。
<mbean
code="org.jboss.util.threadpool.BasicThreadPool"
name="jboss.system:service=ThreadPool">
<attribute name="Name">JBoss System Threads</attribute>
<attribute name="ThreadGroupName">System Threads</attribute>
<attribute name="KeepAliveTime">60000</attribute>
<attribute name="MaximumPoolSize">10</attribute>
<attribute name="MaximumQueueSize">1000</attribute>
<!-- The behavior of the pool when a task is added and the queue is full.
abort - a RuntimeException is thrown
run - the calling thread executes the task
wait - the calling thread blocks until the queue has room
discard - the task is silently discarded without being run
discardOldest - check to see if a task is about to complete and enque
the new task if possible, else run the task in the calling thread
-->
<attribute name="BlockingMode">run</attribute>
</mbean>
我正在尝试在我的代码中访问它,如下所示,
MBeanServer server = MBeanServerLocator.locateJBoss();
MBeanInfo mbeaninfo = server.getMBeanInfo(new ObjectName("jboss.system:service=ThreadPool"));
现在我有了 MBean 信息。我想在 MBean 中定义一个 BasicThreadPool 对象的实例。有可能吗?
我知道一种方法,我们可以从 MBean Info 中获取类名,也可以获取构造实例的属性。有没有更好的方法?
【问题讨论】:
-
以下文章可能会帮助您实现这一目标。尽管它自 2005 年以来就描述了读取 MBean 的要求。 informit.com/guides/content.aspx?g=java&seqNum=160
-
嘿,我已经看过了,根据那篇文章,我们需要从 mbean 服务器获取该对象名称的 ObjectInstance。但这并没有给我一个 BasicThreadPool 对象,但它给了我一个对象'ServerObjectInstance' ..请你澄清一下如何从这个对象中获取 BasicThreadPool 对象。谢谢。
-
考虑使用 RMI。你可以阅读它here