Created
April 7, 2015 12:04
-
-
Save jwlyn/64409fa2c76339c5b2f6 to your computer and use it in GitHub Desktop.
JMX 动态推送参数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import thread.SystemConfig; | |
import javax.management.MBeanServer; | |
import javax.management.ObjectName; | |
import java.lang.management.ManagementFactory; | |
/** | |
* Created by cxu on 2015/4/7. | |
*/ | |
public class Main { | |
private static final int DEFAULT_NO_THREADS = 10; | |
private static final String DEFAULT_SCHEMA = "default"; | |
public static void main(String[] args) throws Exception { | |
// Get the MBean server | |
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | |
// register the MBean | |
SystemConfig mBean = new SystemConfig(DEFAULT_NO_THREADS, DEFAULT_SCHEMA); | |
ObjectName name = new ObjectName("xman:type=SystemConfig"); | |
mbs.registerMBean(mBean, name); | |
do { | |
Thread.sleep(3000); | |
System.out.println("Thread Count=" + mBean.getThreadCount() + ":::Schema Name=" + mBean.getSchemaName()); | |
} while (mBean.getThreadCount() != 0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package thread; | |
/** | |
* Created by cxu on 2015/4/7. | |
*/ | |
public class SystemConfig implements SystemConfigMBean { | |
private int threadCount; | |
private String schemaName; | |
public SystemConfig(int threadCount, String schemaName) | |
{ | |
this.threadCount = threadCount; | |
this.schemaName = schemaName; | |
} | |
@Override | |
public void setThreadCount(int noOfThreads) { | |
threadCount = noOfThreads; | |
} | |
@Override | |
public int getThreadCount() { | |
return threadCount; | |
} | |
@Override | |
public void setSchemaName(String schemaName) { | |
this.schemaName = schemaName; | |
} | |
@Override | |
public String getSchemaName() { | |
return schemaName; | |
} | |
@Override | |
public String doConfig() { | |
return "No of Threads=" + this.threadCount + " and DB Schema Name=" + this.schemaName; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package thread; | |
/** | |
* Created by cxu on 2015/4/7. | |
*/ | |
public interface SystemConfigMBean { | |
public void setThreadCount(int noOfThreads); | |
public int getThreadCount(); | |
public void setSchemaName(String schemaName); | |
public String getSchemaName(); | |
public String doConfig(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment