J2se 5.0 uses Java Management Extensions (JMX) to manage and monitor the Java platform.
Let's test it with an example:
- ImportJava. Lang. Management. classloadingmxbean;
- ImportJava. Lang. Management. compilationmxbean;
- ImportJava. Lang. Management. managementfactory;
- ImportJava. Lang. Management. memorymxbean;
- ImportJava. Lang. Management. memorymanagermxbean;
- ImportJava. Lang. Management. memorypoolmxbean;
- ImportJava. Lang. Management. operatingsystemmxbean;
- ImportJava. Lang. reflect.Invocationtargetexception;
- ImportJava. Lang. reflect.Method;
- ImportJava. util.List;
- Public ClassJdkmbean
- {
- Public Static<T>VoidPrintmxbean (Class<T> T,ObjectObject)
- {
- Method[] Methods = T. getmethods ();
- T instance = (t) object;
- System. Out. printf ("% N --- % s --- % N", T. getname ());
- For(MethodM: methods)
- {
- If(M. getname (). startswith ("get "))
- {
- Try
- {
- ObjectRtvalue = M. Invoke (instance,New Object[0]);
- System. Out. printf ("% s: % S % N", M. getname (). substring (3), rtvalue );
- }
- Catch(IllegalargumentexceptionE1)
- {
- }
- Catch(IllegalaccessexceptionE)
- {
- }
- Catch(InvocationtargetexceptionE)
- {
- }
- }
- }
- }
- Public Static<T>VoidPrintmxbeans (Class<T> T,List<T> List)
- {
- For(T Bean: List)
- {
- Printmxbean (T, bean );
- }
- }
- Public Static VoidMain (String[] ARGs)
- {
- Jdkmbean. printmxbean (operatingsystemmxbean.Class, Managementfactory. getoperatingsystemmxbean ());
- Jdkmbean. printmxbean (compilationmxbean.Class, Managementfactory. getcompilationmxbean ());
- Jdkmbean. printmxbean (classloadingmxbean.Class, Managementfactory. getclassloadingmxbean ());
- Jdkmbean. printmxbean (memorymxbean.Class, Managementfactory. getmemorymxbean ());
- Jdkmbean. printmxbeans (memorymanagermxbean.Class, Managementfactory. getmemorymanagermxbeans ());
- Jdkmbean. printmxbeans (memorypoolmxbean.Class, Managementfactory. getmemorypoolmxbeans ());
- }
- }
Running result:
--- Java. Lang. Management. operatingsystemmxbean ---
Arch: x86
Availableprocessors: 2
Name: Windows 2000
Version: 5.0
--- Java. Lang. Management. compilationmxbean ---
Totalcompilationtime: 5
Name: Hotspot client Compiler
--- Java. Lang. Management. classloadingmxbean ---
Loadedclasscount: 431
Unloadedclasscount: 0
Totalloadedclasscount: 431
--- Java. Lang. Management. memorymxbean ---
Heapmemoryusage: init = 0 (0 k) used = 458288 (447 K) committed = 2031616 (1984 K) max = 66650112 (65088 K)
Nonheapmemoryusage: init = 29556736 (28864 K) used = 12541248 (12247 K) committed = 29851648 (29152 K) max = 121634816 (118784 K)
Objectpendingfinalizationcount: 0
--- Java. Lang. Management. memorymanagermxbean ---
Memorypoolnames: [ljava. Lang. String; @ 6ca1c
Name: codecachemanager
--- Java. Lang. Management. memorymanagermxbean ---
Memorypoolnames: [ljava. Lang. String; @ 1bf216a
Name: Copy
--- Java. Lang. Management. memorymanagermxbean ---
Memorypoolnames: [ljava. Lang. String; @ 12ac982
Name: marksweepcompact
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: NULL
Memorymanagernames: [ljava. Lang. String; @ c20e24
Peakusage: init = 196608 (192 K) used = 482048 (470 K) committed = 491520 (480 K) max = 33554432 (32768 K)
Usage: init = 196608 (192 K) used = 524352 (512 K) committed = 557056 (544 K) max = 33554432 (32768 K)
Usagethreshold: 0
Usagethresholdcount: 0
Name: Code Cache
Type: Non-heap memory
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: init = 524288 (512 K) used = 0 (0 k) committed = 0 (0 k) max = 4194304 (4096 K)
Collectionusagethreshold: 0
Collectionusagethresholdcount: 0
Memorymanagernames: [ljava. Lang. String; @ 2e7263
Peakusage: init = 524288 (512 K) used = 511160 (499 K) committed = 524288 (512 K) max = 4194304 (4096 K)
Usage: init = 524288 (512 K) used = 521688 (509 K) committed = 524288 (512 K) max = 4194304 (4096 K)
Name: Eden Space
Type: heap memory
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: init = 65536 (64 K) used = 0 (0 k) committed = 0 (0 k) max = 458752 (448 K)
Collectionusagethreshold: 0
Collectionusagethresholdcount: 0
Memorymanagernames: [ljava. Lang. String; @ 157f0dc
Peakusage: init = 65536 (64 K) used = 65528 (63 K) committed = 65536 (64 K) max = 458752 (448 K)
Usage: init = 65536 (64 K) used = 65528 (63 K) committed = 65536 (64 K) max = 458752 (448 K)
Name: specified vor Space
Type: heap memory
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: init = 1441792 (1408 K) used = 0 (0 k) committed = 0 (0 k) max = 61997056 (60544 K)
Collectionusagethreshold: 0
Collectionusagethresholdcount: 0
Memorymanagernames: [ljava. Lang. String; @ 863399
Peakusage: init = 1441792 (1408 K) used = 142120 (138 K) committed = 1441792 (1408 K) max = 61997056 (60544 K)
Usage: init = 1441792 (1408 K) used = 142120 (138 K) committed = 1441792 (1408 K) max = 61997056 (60544 K)
Usagethreshold: 0
Usagethresholdcount: 0
Name: tenured gen
Type: heap memory
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: init = 8388608 (8192 K) used = 0 (0 k) committed = 0 (0 k) max = 67108864 (65536 K)
Collectionusagethreshold: 0
Collectionusagethresholdcount: 0
Memorymanagernames: [ljava. Lang. String; @ a59698
Peakusage: init = 8388608 (8192 K) used = 641040 (626 K) committed = 8388608 (8192 K) max = 67108864 (65536 K)
Usage: init = 8388608 (8192 K) used = 641040 (626 K) committed = 8388608 (8192 K) max = 67108864 (65536 K)
Usagethreshold: 0
Usagethresholdcount: 0
Name: perm gen
Type: Non-heap memory
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: init = 8388608 (8192 K) used = 0 (0 k) committed = 0 (0 k) max = 8388608 (8192 K)
Collectionusagethreshold: 0
Collectionusagethresholdcount: 0
Memorymanagernames: [ljava. Lang. String; @ 141d683
Peakusage: init = 8388608 (8192 K) used = 5601632 (5470 K) committed = 8388608 (8192 K) max = 8388608 (8192 K)
Usage: init = 8388608 (8192 K) used = 5601632 (5470 K) committed = 8388608 (8192 K) max = 8388608 (8192 K)
Usagethreshold: 0
Usagethresholdcount: 0
Name: perm Gen [Shared-ro]
Type: Non-heap memory
--- Java. Lang. Management. memorypoolmxbean ---
Collectionusage: init = 12582912 (12288 K) used = 0 (0 k) committed = 0 (0 k) max = 12582912 (12288 K)
Collectionusagethreshold: 0
Collectionusagethresholdcount: 0
Memorymanagernames: [ljava. Lang. String; @ 16a55fa
Peakusage: init = 12582912 (12288 K) used = 5850024 (5712 K) committed = 12582912 (12288 K) max = 12582912 (12288 K)
Usage: init = 12582912 (12288 K) used = 5850024 (5712 K) committed = 12582912 (12288 K) max = 12582912 (12288 K)
Usagethreshold: 0
Usagethresholdcount: 0
Name: perm Gen [Shared-RW]
Type: Non-heap memory