我正在尝试jboss-service.xml
使用MBean 绑定服务类的实例。
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信息。我想要一个BasicThreadPool
在MBean中定义的对象的实例。可能吗 ?
我知道一种方法,我们可以从MBean Info中获取类名称,也可以获取用于构造实例的属性。有什么更好的方法吗?
正如skaffman所指出的,您不能直接获取线程池的直接实例,但是使用MBeanServerInvocationHandler可以使您更加接近。
import org.jboss.util.threadpool.BasicThreadPoolMBean;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
.....
BasicThreadPoolMBean threadPool = (BasicThreadPoolMBean)MBeanServerInvocationHandler.newProxyInstance(MBeanServerLocator.locateJBoss(); new ObjectName("jboss.system:service=ThreadPool"), BasicThreadPoolMBean.class, false);
该示例中的 threadPool 实例现在实现了基础线程池服务的所有方法。
请注意,如果只需要它来提交要执行的任务,则只需要一件事情,那就是 Instance 属性,该属性[几乎]是相同的接口,因此您也可以这样做:
import org.jboss.util.threadpool.ThreadPool;
import javax.management.ObjectName;
.....
ThreadPool threadPool = (ThreadPool)MBeanServerLocator.locateJBoss().getAttribute(new ObjectName("jboss.system:service=ThreadPool"), "Instance");
....但不是远程的,仅在同一VM中。
我正在使用Guice开发一个小型web框架。我有一个Router对象,一旦初始化,它就会公开一个getControllerClasses()方法。我必须循环所有这些动态返回的类,以使用Guice绑定它们。 我绑定路由器: 但是,我如何在一个模块中获得绑定的路由器实例,以便也可以绑定其getControllerClasses()方法返回的类? 我能够在模块中获取路由器实例的唯一方法是,将该实例绑定到
rank ▲ ✰ vote url 56 390 59 554 url 如何获取实例的类名 如何才能获取一个实例对象的类名? 我想或许the inspect module可以实现,但是好像还没有发现什么能帮我的.或许可以分析__class__成员,但是我不知道怎么用. 你试没试类里的__name__属性?比如x.__class__.__name__或许可以得到你想要的 >>> import ite
这不起作用: “绑定不匹配:类型不能有效替代类型的有界参数”
我有以下代码: 生日属性的类型为java.time。LocalDate,并且属于类Person。因为我使用JPA,所以我不想使用JavaFX属性。上述代码无法编译。编译器的错误消息是: 我该如何解决这个问题? 更新:我的个人类具有以下代码: 控制器类:
我有以下类桥联图: 我将JUnit测试用例编写为: 但我不知道该断言什么:
我使用以下方法获取应用程序名和packageName,但我需要iPhone用户的捆绑id。我想共享一个应用程序链接。我在Android上做的,但在iPhone上,我需要bundle id。