A new tool JCONSOLE is available in JDK1.5 to observe the operation and other conditions. For JMX, JConsole can view the property and operation methods of MBean under the graphical interface, so you don't have to add HTMLADAPTORSERVER to view :).
Let us look at the code. (Hellombean.java and Hello.java and the original no change)
Hellombean.java
/ *
* CREATED ON
2005-3-17
* @Author roson
*
* /
Package bean;
Public interface hellombean {
Public void syhello ();
Public String getMessage ();
Public void setmessage (string message);
Public int getChangecount ();
Public void resetcounter ();
}
Hello.java
/ *
* CREATED ON
2005-3-17
* @Author roson
*
* /
Package bean;
Import javax.management. *;
Public Class Hello Extends NotificationBroadcastersupport IMPLEments Hellombean {
PRIVATE STRING MESSAGE
PRIVATE INT CHANGECOUNT;
PRIVATE long sequencenumber = 1;
Public string getMessage () {
Return Message;
}
Public void setmessage (string message) {
THIS.MESSAGE = Message;
ChangeCount ;
Notification Notification = New Notification ("Bean / Hello",
this,
Sequencenumber ,
System.currentTimeMillis (),
Message);
SendNotification (Notification);
}
Public int getChangecount () {
Return ChangeCount;
}
Public void resetcounter ()
{
ChangeCount = 0;
}
Public void sayhello ()
{
System.out.println ("Hi, World");
}
}
Then let's see HelloAgent.java.
/ *
* CREATED ON
2005-3-17
* @Author roson
*
* /
Package bean;
Import com.sun.jdmk.comm. *;
Import java.lang.management. *;
Import javax.management. *;
Public class helloagent {
Public static void main (String [] args) {
MBeanServer Server = managementFactory.getPlatformmbeanserver ();
HTMLADAPTORSERVER Adaptor = New HTMLADAPTORSERVER ();
Hellombean hello1 = new hello ();
Hellombean Hello2 = New Hello ();
Try
{
Objectname HelloObjectName1 = New ObjectName ("Bean: Type = Hello, Name = Hello1"); Server.Registermbean (Hello1, HelloObjectName1);
ObjectName HelloObjectName2 = New ObjectName ("bean: type = hello, name = hello2");
Server.registermbean (Hello2, HelloObjectName2);
Objectname AdaptorObjectName = New ObjectName ("HelloServer: Type = HTMLADAPTOR, Port = 8082");
Adaptor.Setport (8082);
Server.Registermbean (Adaptor, AdaptorObjectName);
Adaptor.start ();
System.out.println ("Waiting..");
Thread.sleep (long.max_value);
}
Catch (InterruptedException E)
{
System.out.println ("Sleep Stoped");
E.PrintStackTrace ();
}
Catch (MalformedObjectnameException E)
{
System.out.println ("Bad ObjectName");
E.PrintStackTrace ();
}
Catch (InstanceAlReadyexistSexception E)
{
System.out.println ("Already EXITS");
}
Catch (MBeanRegistrationException E)
{
System.out.println ("Registeration Error");
}
Catch (NotcompliantmbeaneXception E)
{
System.out.println ("Registeration Error");
}
}
}
The change I have already separated from the red color area. If you can refer to and the previous difference if the property. I also added HTMLADAPTORSERVER here.
run:
1, compile (this is not to say, of course, some packages are going to add.
2, java -dcom.sun.management.jmxremote HelloAgent
3, run JCONSOLE (in JDK)
1.5.0
_02 / bin / jconsole.exe)
4, jump out of the dialog, if you have PID, you can connect it. Next, everyone is familiar with this tool.
Reference: http://java.sun.com/j2se/1.5.0/docs/guide/jmx/tutorial/essential.html#wp1053244