1.文件目录
2.需要jdmkrt.jar附件可下载
3.创建 HelloMBean
package jmx.helloworld;
/**
* HelloMBean定义方法及属性由Hello实现
*/
public interface HelloMBean {
// operations
public void sayHello();
public int add(int x, int y);
// attributes
// a read-only attribute called Name of type String
public String getName();
// a read-write attribute called CacheSize of type int
public int getCacheSize();
public void setCacheSize(int size);
}
4.创建Hello实现HelloMBean接口,
package jmx.helloworld;
/**
* 被监控的HelloBean
* @author chenyw
*
*/
public class Hello implements HelloMBean {
private final String name = "Reginald";
private static final int DEFAULT_CACHE_SIZE = 200;
private int cacheSize = DEFAULT_CACHE_SIZE;
public void sayHello() {
System.out.println("hello, world");
}
public int add(int x, int y) {
System.out.println("x+y="+(x+y));
return x + y;
}
/*
* Getter for the Name attribute. The pattern shown here is frequent: the
* getter returns a private field representing the attribute value. In our
* case, the attribute value never changes, but for other attributes it
* might change as the application runs. Consider an attribute representing
* statistics such as uptime or memory usage, for example. Being read-only
* just means that it can't be changed through the management interface.
*/
public String getName() {
return this.name;
}
/*
* Getter for the CacheSize attribute. The pattern shown here is frequent:
* the getter returns a private field representing the attribute value, and
* the setter changes that field.
*/
public int getCacheSize() {
return this.cacheSize;
}
/*
*synchronized在多线程操作时能确保数据的唯一性
*/
public synchronized void setCacheSize(int size) {
this.cacheSize = size;
/*
*
*
* 当设置CacheSize的值时控制台打印显示
*
*/
System.out.println("Cache size now " + this.cacheSize);
}
}
5.创建HelloAgent
package jmx.helloworld;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import com.sun.jdmk.comm.HtmlAdaptorServer;
/**
*
*该类是一个Agent类,说明: 先创建了一个MBeanServer,用来做MBean的容器
* 将Hello这个类注入到MBeanServer中,注入需要创建一个ObjectName类
* 创建一个AdaptorServer,这个类将决定MBean的管理界面,这里用最普通的Html型界面。 AdaptorServer其实也是一个MBean。
* jmx.hello:name=Hello的名字是有一定规则的,格式为:“域名:name=MBean名称”,
* 域名和MBean名称都可以任意取。 打开网页:http://localhost:8082/
*
*/
public class HelloAgent {
public static void main(String[] args) throws Exception {
// 创建一个MBeanServer,用来做MBean的容器
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// 将Hello这个类注入到MBeanServer中,注入需要创建一个ObjectName类
ObjectName helloAdaptor = new ObjectName(
"jmx.hello:name=Hello");
mbs.registerMBean(new Hello(), helloAdaptor);
ObjectName htmlAdaptorON = new ObjectName(
"jmx.agent:name=HelloAgent,port=8082");
// 创建一个AdaptorServer,这个类将决定MBean的管理界面,这里用最普通的Html型界面
HtmlAdaptorServer htmlAdaptor = new HtmlAdaptorServer();
mbs.registerMBean(htmlAdaptor, htmlAdaptorON);
System.out.println("Starting the HtmlAdaptor....");
htmlAdaptor.start();
}
}
6.运行HelloAgent ,然后打开网页http://localhost:8082 如图所示
可以看到被监控HelloBean,点击进去可设置里面的值。如CacheSize 将value值设置为400,点击Apply
控制台打印为
Cache size now 400
- 大小: 6.9 KB
- 大小: 56.4 KB
- 大小: 82.5 KB
分享到:
相关推荐
NULL 博文链接:https://hintcnuie.iteye.com/blog/255815
HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote"); out.println(helloworld.SayHello("佛山人")); 5.用ant或eclipse,把客户端文件打成war包,发布到jboss上 6.输入...
│ HelloWorld.rar JBoss+Tomcat+Eclipse集成(实例演示) │ ├─ch26 │ eclipse_helloworld.rar Eclipse+Tomcat集成(实例演示) │ ├─ch27 │ netbeans_helloworld.rar NetBeans+Tomcat集成(实例演示) │ ├─...
3.1 HelloWorld实例 3.2 程序代码 3.3 配置文件jboss-service.xml 3.4 将实例部署到JBOSS 3.5 MBean的效果 s四.EJB3.0使用说明 1. Enterprice JavaBeans(EJB)的概念 1.1 会话 Bean: 1.2 实体Bean: 1.3 消息驱动...
Version 5 Hello World(你好) Version 5 Initial Configuration(初始化配置) Version 5 Installation(安装) Version 5 Performance Tuning(性能调整) Version 5 Run Broker(运行代理) ...
Jetty和Maven HelloWorld教程 Jetty(6)入门 (www.itjungle.com) Jetty Start.jar 配置Jetty 如何设置上下文(Context Path) 如何知道使用了那些jar包 如何配置SSL 如何使用非root用户监听80端口 如何配置连接器...
java8流源码你好,世界 Me test repository AO test No. 1! :) ...#我需要的一组技术:领域驱动设计?...boot(呃,不适用于我想控制所有的大型应用程序......)TestDrivenDevelopment ...JMS、JMX、JTA Message
10.3 利用Spring在JSP页面输出“HelloWorld”的示例 10.3.1 建立myHelloWorld工程 10.3.2 编写JSP页面helloWorld.jsp 10.3.3 编写控制器HelloWorldController.java 10.3.4 建立Spring的配置文档dispatcherServlet-...
10.3 利用Spring在JSP页面输出“HelloWorld”的示例 10.3.1 建立myHelloWorld工程 10.3.2 编写JSP页面helloWorld.jsp 10.3.3 编写控制器HelloWorldController.java 10.3.4 建立Spring的配置文档dispatcherServlet-...
10.3 利用Spring在JSP页面输出“HelloWorld”的示例 10.3.1 建立myHelloWorld工程 10.3.2 编写JSP页面helloWorld.jsp 10.3.3 编写控制器HelloWorldController.java 10.3.4 建立Spring的配置文档dispatcherServlet-...
10.3 利用Spring在JSP页面输出“HelloWorld”的示例 10.3.1 建立myHelloWorld工程 10.3.2 编写JSP页面helloWorld.jsp 10.3.3 编写控制器HelloWorldController.java 10.3.4 建立Spring的配置文档dispatcherServlet-...
Clustered Helloworld-cluster application 317 Updating workers.properties 317 Farming 320 Cluster member configuration 320 This material is copyright and is licensed for the sole use by Jillian ...
使用BeanPostProcessor的Hello World示例 3.7.1.2. RequiredAnnotationBeanPostProcessor示例 3.7.2. 用BeanFactoryPostProcessor定制配置元数据 3.7.2.1. PropertyPlaceholderConfigurer示例 3.7.2.2. ...
Indeed, the fact that a simple Spring Boot Hello World application can fit into a tweet is a radical departure from what the same functionality required on the vm only a few short years ago. Out-of-...
目录 ..........................................................................................................................I 译者声明..................................................................
Java访问权限控制,为Java操作文件、写入文件分配合适的权限,定义写到文件的信息、定义文件,输出到c:/hello.txt、写信息到文件、关闭输出流。 Java绘制图片火焰效果 1个目标文件 摘要:Java源码,图形操作,火焰...
Java访问权限控制,为Java操作文件、写入文件分配合适的权限,定义写到文件的信息、定义文件,输出到c:/hello.txt、写信息到文件、关闭输出流。 Java绘制图片火焰效果 1个目标文件 摘要:Java源码,图形操作,火焰...