Package com. Wonder;
Import java. Lang. Management. classloadingmxbean;
Import java. Lang. Management. garbagecollectormxbean;
Import java. Lang. Management. managementfactory;
Import java. Lang. Management. memorymxbean;
Import java. Lang. Management. memoryusage;
Import java. Lang. Management. runtimemxbean;
Import java. util. List;
Public class testmain extends thread {
Runtimemxbean mxbean;
Private void setfactory (){
Mxbean = managementfactory. getruntimemxbean ();
// Obtain the attributes of the Virtual Machine
System. out. println ("===================== virtual machine information =======================" );
System. Out. println ("virtual machine provider:" + mxbean. getvmvendor ());
System. Out. println ("Virtual Machine name:" + mxbean. getvmname ());
System. Out. println ("current class path:" + mxbean. getclasspath ());
System. Out. println ("process number @ machine:" + mxbean. getname ());
System. Out. println ("running time (MS):" + mxbean. getuptime ());
// Class Management Interface
System. out. println ("===================== class loading information ============================ ");
Classloadingmxbean aclassloadingmxbean = managementfactory
. Getclassloadingmxbean ();
System. Out. println ("Total number of loaded classes :"
+ Aclassloadingmxbean. getloadedclasscount ());
System. Out. println ("verbose status:" + aclassloadingmxbean. isverbose ());
// Memory Management Interface
System. out. println ("===================== memory information ========================== = ");
Memorymxbean amemorymxbean = managementfactory. getmemorymxbean ();
System. Out. println ("number of terminated pending instances :"
+ Amemorymxbean. getobjectpendingfinalizationcount (); // returns the approximate number of objects whose suspension is terminated.
// Return the current usage of non-heap memory used by the Java Virtual Machine
Memoryusage amemoryusage = amemorymxbean. getnonheapmemoryusage (); // memory obtained from the system (in bytes) when the VM is started)
System. Out. println ("memory obtained from the system during VM startup:" + amemoryusage. getinit (); // indicates the amount of memory in use (in bytes)
System. Out. println ("memory used currently:" + amemoryusage. getused (); // indicates that
// Java
// The amount of memory used by the VM (in bytes)
System. Out. println ("amount of memory used by the VM:" + amemoryusage. getcommitted (); // indicates the maximum amount of memory that can be used for memory management (in bytes)
System. Out. println ("Initial memory size for memory management:" + amemoryusage. getinit ());
System. Out. println ("maximum memory size for memory management:" + amemoryusage. getmax ());
System. Out. println ("Overall description:" + amemoryusage. tostring ());
List <garbagecollectormxbean> agcmxbeans = managementfactory. getgarbagecollectormxbeans ();
Garbagecollectormxbean agcmxbean = agcmxbeans. Get (0 );
System. out. println ("=================== GC information ============================ = ");
System. Out. println ("Total number of collections:" + agcmxbean. getcollectioncount ());
System. Out. println ("collection time:" + agcmxbean. getcollectiontime ());
System. Out. println ("Memory Manager valid:" + agcmxbean. isvalid ());
System. Out. println ("Memory Pool name:" + agcmxbean. getmemorypoolnames () [0]);
System. Out. println ("Memory Pool name:" + agcmxbean. getmemorypoolnames () [1]);
System. out. println ("****************** end ******************* ***");
}
Public void run (){
Try {
While (true ){
Setfactory ();
Sleep (1000 );
}
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
Public static void main (string [] ARGs ){
Testmain atest = new testmain ();
Atest. Start ();
}
}