Monitoring and management of new j2se5.0 features

Source: Internet
Author: User

J2se 5.0 uses Java Management Extensions (JMX) to manage and monitor the Java platform.
Let's test it with an example:

  1. ImportJava. Lang. Management. classloadingmxbean;
  2. ImportJava. Lang. Management. compilationmxbean;
  3. ImportJava. Lang. Management. managementfactory;
  4. ImportJava. Lang. Management. memorymxbean;
  5. ImportJava. Lang. Management. memorymanagermxbean;
  6. ImportJava. Lang. Management. memorypoolmxbean;
  7. ImportJava. Lang. Management. operatingsystemmxbean;
  8. ImportJava. Lang. reflect.Invocationtargetexception;
  9. ImportJava. Lang. reflect.Method;
  10. ImportJava. util.List;
  11. Public ClassJdkmbean
  12. {
  13. Public Static<T>VoidPrintmxbean (Class<T> T,ObjectObject)
  14. {
  15. Method[] Methods = T. getmethods ();
  16. T instance = (t) object;
  17. System. Out. printf ("% N --- % s --- % N", T. getname ());
  18. For(MethodM: methods)
  19. {
  20. If(M. getname (). startswith ("get "))
  21. {
  22. Try
  23. {
  24. ObjectRtvalue = M. Invoke (instance,New Object[0]);
  25. System. Out. printf ("% s: % S % N", M. getname (). substring (3), rtvalue );
  26. }
  27. Catch(IllegalargumentexceptionE1)
  28. {
  29. }
  30. Catch(IllegalaccessexceptionE)
  31. {
  32. }
  33. Catch(InvocationtargetexceptionE)
  34. {
  35. }
  36. }
  37. }
  38. }
  39. Public Static<T>VoidPrintmxbeans (Class<T> T,List<T> List)
  40. {
  41. For(T Bean: List)
  42. {
  43. Printmxbean (T, bean );
  44. }
  45. }
  46. Public Static VoidMain (String[] ARGs)
  47. {
  48. Jdkmbean. printmxbean (operatingsystemmxbean.Class, Managementfactory. getoperatingsystemmxbean ());
  49. Jdkmbean. printmxbean (compilationmxbean.Class, Managementfactory. getcompilationmxbean ());
  50. Jdkmbean. printmxbean (classloadingmxbean.Class, Managementfactory. getclassloadingmxbean ());
  51. Jdkmbean. printmxbean (memorymxbean.Class, Managementfactory. getmemorymxbean ());
  52. Jdkmbean. printmxbeans (memorymanagermxbean.Class, Managementfactory. getmemorymanagermxbeans ());
  53. Jdkmbean. printmxbeans (memorypoolmxbean.Class, Managementfactory. getmemorypoolmxbeans ());
  54. }
  55. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.