how to modify ThreadPoolTaskExecutor at runtime through jmx

旧巷老猫 提交于 2019-12-04 16:49:22

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.

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

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>

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

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 .

Hope this helps,

Cyrille

Use super to call the method in the superclass, to avoid the infinite loop:

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

You need super.setCorePoolSize(corePoolSize);

If I understand correctly, you initialize the pool with a core size of 5, but then at runtime, reset the pool size to 1. When you say, "the ongoing process which still has 5 TaskExecutor threads still going", is that 5 busy threads, or 5 idle threads ?

If they are busy, you core size reset will not take effect until the 4 "excess" threads become idle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!