我在通过 JConsole 修改 MBean 属性时遇到问题。我有一个 Threading bean,它通过以下方式调用:
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 包含所有默认属性值。
SimpleJmxAgent 看起来像:
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();
}
我从 ThreadPoolTaskExecutor 继承了 ThreadPoolManager,以便让它能够访问 Thread 属性的 getter 和 setter 方法,例如:public void setCorePoolSize(int corePoolSize)
EDIT:
我已经实现了使用:
public void setCorePoolSize(int corePoolSize){
super.setCorePoolSize(corePoolSize);
}
包裹在:
public void changeCorePoolSize(int x){
setCorePoolSize(x);
}
现在,操作出现在 MBeans 选项卡中。然而,属性显示为与所使用的不同的值。我已经在 ThreadContext.xml 中设置
property name="corePoolSize" value="5"
然而,当查看属性设置为 1 时,这是默认值。我可以通过 Jconsole 更改此设置changeCorePoolSize
操作,但只有一个装饰效果,改变显示的值,但不改变正在进行的过程,该过程仍然有 5TaskExecutor
线程仍在继续。
我在做的事情中是否遗漏了一些东西?什么可能导致我通过 ThreadContext.xml 设置的属性与 Jconsole 属性中显示的属性之间断开连接?