如何在运行时通过jmx修改ThreadPoolTask​​Executor [英] how to modify ThreadPoolTaskExecutor at runtime through jmx

查看:195
本文介绍了如何在运行时通过jmx修改ThreadPoolTask​​Executor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过JConsole修改我的MBean属性。我有一个调用的Threading bean:

I'm having trouble modifying my MBean properties through JConsole. I have a Threading bean which invoked with:

public static void main(String[] args) throws Exception {
    // JMX
    new SimpleJmxAgent();

    // spring executor context
    ApplicationContext ctx = new FileSystemXmlApplicationContext(
            "src/resources/ThreadContent.xml");

    startThreads(ctx);
}

private static void startThreads(ApplicationContext ctx) {

    TaskExecutor tE = (TaskExecutor) ctx.getBean("TaskExecutor");

    System.out.println("Starting threads");

    for (int i = 0; i < 10; i++) {
        tE.execute(new RepeatingGrpPoC());
    }

ThreadContent.xml包含所有默认属性值。

ThreadContent.xml contains all default property values.

SimpleJmxAgent看起来像:

SimpleJmxAgent looks like:

public SimpleJmxAgent() {

    mbs = ManagementFactory.getPlatformMBeanServer();

    // Spring context - used to load MBeans
    XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(
            "resources/JMXcontent.xml"));

    // Unique identification of MBeans
    ThreadPoolManager threadBean = (ThreadPoolManager) factory.getBean("ThreadPoolBean");
    ObjectName threadName = null;

      try {
          // Uniquely identify the MBeans and register them with the platform MBeanServer 
          threadName = new ObjectName("THREADING:name=ThreadBean");
          mbs.registerMBean(threadBean, threadName);
       } catch(Exception e) {
          e.printStackTrace();
       }

我从ThreadPoolTask​​Executor获取ThreadPoolManager,以便让它访问getter和Thread属性的setter方法,例如:
public void setCorePoolSize(int corePoolSize)

I have the ThreadPoolManager inherting from ThreadPoolTaskExecutor in order to give it access to the getter and setter methods of the Thread properties such as: public void setCorePoolSize(int corePoolSize)

编辑:

我已实施使用:

public void setCorePoolSize(int corePoolSize){
    super.setCorePoolSize(corePoolSize);
}

包裹在:

    public void changeCorePoolSize(int x){
    setCorePoolSize(x);

}

所以现在操作出现在MBeans选项卡中。但是,属性显示为与正在使用的值不同的值。我在我的ThreadContext.xml中设置了

So now the Operation appears in MBeans tab. However the Attributes are shown as different values as what is being used. I have set in my ThreadContext.xml

property name="corePoolSize" value="5"

然而,当查看属性设置为1时,这是一个默认值。我可以通过 changeCorePoolSize 操作通过Jconsole进行更改,但只有一个修饰效果更改显示的值,但不会更改仍然有5 的正在进行的进程TaskExecutor
线程仍在继续。

However when viewing attribute is set to 1 which is a default value. I can change this through the Jconsole via the changeCorePoolSize operation but has only a cosmetic effect changing the value displayed but not changing the ongoing process which still has 5 TaskExecutor threads still going.

我错过了我正在做的事情吗?什么可能导致我通过ThreadContext.xml设置的属性与Jconsole中的属性中显示的属性之间断开连接?

Am I missing something in what I am doing? What could causing the disconnect between the properties I'm setting through ThreadContext.xml and that being displayed in the attributes in Jconsole?

推荐答案

减少CorePoolSize应该足以减少活动线程的数量,但只有在当前运行的命令完成后才会生效。

Reducing the CorePoolSize should be enough to reduce the the number of active thread but it only takes effect after the currently running commands complete.

请注意MaxPoolSize可能会产生的影响如果workQueue已满,则增加活动线程数。

Beware of the effect of MaxPoolSize wich may increse the number of active threads if the workQueue is full.

如果您有兴趣,我们打包了 JMX启用了util.concurrent ThreadPoolExecutor 并通过简单的基于Spring XML命名空间的配置公开它。它公开了指标(activeCount,completedTackCount等)和运行时配置参数(corePoolsize,maxPoolsize)。
您只需声明:

If you are interested, we packaged a JMX enabled util.concurrent ThreadPoolExecutor and expose it via a simple spring XML namespaced based configuration. It exposes both metrics (activeCount, completedTackCount, etc) and runtime configuration parameters (corePoolsize, maxPoolsize). You simply have to declare :

<beans 
   xmlns:management="http://www.xebia.fr/schema/xebia-management-extras"
   ... >

   <!-- MBeanExporter is in charge of registering the ExecutorService MBean -->
   <context:mbean-export />

   <management:executor-service 
       id="my-executor" 
       pool-size="1-10" 
       queue-capacity="5"
       keep-alive="5"
       rejection-policy="ABORT" />
   ...
<beans>

该库包含JSP页面和Hyperic HQ插件监视这些线程池。

The library contains JSP page and an Hyperic HQ plugin to monitor these thread pools.

这< executor-service />与许多其他JMX附加程序一起打包,以便于监视常见组件(dbcp,util.concurrent,cxf,jms等),并在 http://code.google.com/p/xebia-france/wiki/XebiaManagementExtras

This <executor-service /> is packaged with many other JMX extras to ease monitoring of common components (dbcp, util.concurrent, cxf, jms, etc) and proposed under a business friendly Apache Software License at http://code.google.com/p/xebia-france/wiki/XebiaManagementExtras .

希望这会有所帮助,

Cyrille

这篇关于如何在运行时通过jmx修改ThreadPoolTask​​Executor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆