java可视化显示内存使用情况.docx
- 文档编号:2776116
- 上传时间:2022-11-15
- 格式:DOCX
- 页数:31
- 大小:90.17KB
java可视化显示内存使用情况.docx
《java可视化显示内存使用情况.docx》由会员分享,可在线阅读,更多相关《java可视化显示内存使用情况.docx(31页珍藏版)》请在冰豆网上搜索。
java可视化显示内存使用情况
Java代码
1.package memoryManage;
2.
3./*
4. * @(#)MemoryMonitor.java 1.3 05/11/17
5. *
6. * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
7. *
8. * Redistribution and use in source and binary forms, with or without
9. * modification, are permitted provided that the following conditions are met:
10. *
11. * -Redistribution of source code must retain the above copyright notice, this
12. * list of conditions and the following disclaimer.
13. *
14. * -Redistribution in binary form must reproduce the above copyright notice,
15. * this list of conditions and the following disclaimer in the documentation
16. * and/or other materials provided with the distribution.
17. *
18. * Neither the name of Sun Microsystems, Inc. or the names of contributors may
19. * be used to endorse or promote products derived from this software without
20. * specific prior written permission.
21. *
22. * This software is provided "AS IS," without a warranty of any kind. ALL
23. * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
24. * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
25. * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
26. * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
27. * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
28. * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
29. * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
30. * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
31. * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
32. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33. *
34. * You acknowledge that this software is not designed, licensed or intended
35. * for use in the design, construction, operation or maintenance of any
36. * nuclear facility.
37. */
38.
39./*
40. * @(#)MemoryMonitor.java 1.3 05/11/17
41. */
42.
43.import java.awt.*;
44.import java.awt.event.*;
45.import java.awt.image.BufferedImage;
46.import java.awt.geom.Line2D;
47.import java.awt.geom.Rectangle2D;
48.import java.util.Date;
49.import javax.swing.*;
50.import javax.swing.border.EtchedBorder;
51.import javax.swing.border.TitledBorder;
52.import java.lang.management.*;
53.import java.util.*;
54.
55./**
56. * Demo code which plots the memory usage by all memory pools. The memory usage
57. * is sampled at some time interval using java.lang.management API. This demo
58. * code is modified based java2d MemoryMonitor demo.
59. */
60.class MemoryMonitor extends JPanel {
61.
62. static JCheckBox dateStampCB = new JCheckBox("Output Date Stamp");
63. public Surface surf;
64. JPanel controls;
65. boolean doControls;
66. JTextField tf;
67. // Get memory pools.
68. static java.util.List
69. .getMemoryPoolMXBeans();
70. // Total number of memory pools.
71. static int numPools = mpools.size();
72.
73. public MemoryMonitor() {
74. setLayout(new BorderLayout());
75. setBorder(new TitledBorder(new EtchedBorder(), "Memory Monitor"));
76. add(surf = new Surface());
77. controls = new JPanel();
78. controls.setPreferredSize(new Dimension(135, 80));
79. Font font = new Font("serif", Font.PLAIN, 10);
80. JLabel label = new JLabel("Sample Rate");
81. label.setFont(font);
82. label.setForeground(Color.red);
83. controls.add(label);
84. tf = new JTextField("1000");
85. tf.setPreferredSize(new Dimension(45, 20));
86. controls.add(tf);
87. controls.add(label = new JLabel("ms"));
88. label.setFont(font);
89. label.setForeground(Color.red);
90. controls.add(dateStampCB);
91. dateStampCB.setFont(font);
92. addMouseListener(new MouseAdapter() {
93. public void mouseClicked(MouseEvent e) {
94. removeAll();
95. if ((doControls = !
doControls)) {
96. surf.stop();
97. add(controls);
98. } else {
99. try {
100. surf.sleepAmount = Long.parseLong(tf.getText().trim());
101. } catch (Exception ex) {
102. }
103. surf.start();
104. add(surf);
105. }
106.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 可视化 显示 内存 使用 情况