- 浏览: 458792 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (272)
- java基础 (59)
- struts (8)
- spring (8)
- 数据库 (8)
- java 网络编程 (29)
- hibernate (3)
- JavaScript (10)
- 日志管理 (2)
- jsp (4)
- servlet (7)
- xml (4)
- ajax (2)
- web service (4)
- 算法与数据结构 (13)
- java 反射机制 (11)
- java 泛型 (3)
- java I/O (8)
- java 线程 (12)
- JavaEE (6)
- java解惑 (33)
- 工具 (5)
- MyEclipse编程实践 (1)
- OSGI (2)
- 设计模式 (9)
- 正则表达式 (0)
- EJB (3)
- Ubuntu linux (6)
- Android (1)
- web前端 (2)
- 找工作 (1)
- SCA (1)
- maven (1)
- 缓存 (1)
- json (1)
- javamail (1)
- 工作笔记 (2)
最新评论
-
霜花似雪:
博主可以分享一下源码吗?
使用maven构建web项目实例 -
王庆波-行:
很好的demo!
memcache使用实例 -
surpassno:
大写的牛逼
java可视化显示内存使用情况 -
zhulin0504:
怎么访问NetEcho.html页面呀???
applet与servlet的网络通信 -
springdata:
java多线程实例demo源代码下载:http://www.z ...
java多线程例子
package memoryManage; /* * @(#)MemoryMonitor.java 1.3 05/11/17 * * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * -Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * -Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. or the names of contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. */ /* * @(#)MemoryMonitor.java 1.3 05/11/17 */ import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.util.Date; import javax.swing.*; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import java.lang.management.*; import java.util.*; /** * Demo code which plots the memory usage by all memory pools. The memory usage * is sampled at some time interval using java.lang.management API. This demo * code is modified based java2d MemoryMonitor demo. */ class MemoryMonitor extends JPanel { static JCheckBox dateStampCB = new JCheckBox("Output Date Stamp"); public Surface surf; JPanel controls; boolean doControls; JTextField tf; // Get memory pools. static java.util.List<MemoryPoolMXBean> mpools = ManagementFactory .getMemoryPoolMXBeans(); // Total number of memory pools. static int numPools = mpools.size(); public MemoryMonitor() { setLayout(new BorderLayout()); setBorder(new TitledBorder(new EtchedBorder(), "Memory Monitor")); add(surf = new Surface()); controls = new JPanel(); controls.setPreferredSize(new Dimension(135, 80)); Font font = new Font("serif", Font.PLAIN, 10); JLabel label = new JLabel("Sample Rate"); label.setFont(font); label.setForeground(Color.red); controls.add(label); tf = new JTextField("1000"); tf.setPreferredSize(new Dimension(45, 20)); controls.add(tf); controls.add(label = new JLabel("ms")); label.setFont(font); label.setForeground(Color.red); controls.add(dateStampCB); dateStampCB.setFont(font); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { removeAll(); if ((doControls = !doControls)) { surf.stop(); add(controls); } else { try { surf.sleepAmount = Long.parseLong(tf.getText().trim()); } catch (Exception ex) { } surf.start(); add(surf); } validate(); repaint(); } }); } public class Surface extends JPanel implements Runnable { public Thread thread; public long sleepAmount = 1000; public int usageHistCount = 20000; private int w, h; private BufferedImage bimg; private Graphics2D big; private Font font = new Font("Times New Roman", Font.PLAIN, 11); private int columnInc; private float usedMem[][]; private int ptNum[]; private int ascent, descent; private Rectangle graphOutlineRect = new Rectangle(); private Rectangle2D mfRect = new Rectangle2D.Float(); private Rectangle2D muRect = new Rectangle2D.Float(); private Line2D graphLine = new Line2D.Float(); private Color graphColor = new Color(46, 139, 87); private Color mfColor = new Color(0, 100, 0); private String usedStr; public Surface() { setBackground(Color.black); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (thread == null) start(); else stop(); } }); int i = 0; usedMem = new float[numPools][]; ptNum = new int[numPools]; } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { return new Dimension(135, 80); } public void paint(Graphics g) { if (big == null) { return; } big.setBackground(getBackground()); big.clearRect(0, 0, w, h); h = h / ((numPools + numPools % 2) / 2); w = w / 2; int k = 0; // index of memory pool. for (int i = 0; i < 2; i++) { for (int j = 0; j < (numPools + numPools % 2) / 2; j++) { plotMemoryUsage(w * i, h * j, w, h, k); if (++k >= numPools) { i = 3; j = (numPools + numPools % 2) / 2; break; } } } g.drawImage(bimg, 0, 0, this); } public void plotMemoryUsage(int x1, int y1, int x2, int y2, int npool) { MemoryPoolMXBean mp = mpools.get(npool); float usedMemory = mp.getUsage().getUsed(); float totalMemory = mp.getUsage().getMax(); // .. Draw allocated and used strings .. big.setColor(Color.green); // Print Max memory allocated for this memory pool. big.drawString(String.valueOf((int) totalMemory / 1024) + "K Max ", x1 + 4.0f, (float) y1 + ascent + 0.5f); big.setColor(Color.yellow); // Print the memory pool name. big.drawString(mp.getName(), x1 + x2 / 2, (float) y1 + ascent + 0.5f); // Print the memory used by this memory pool. usedStr = String.valueOf((int) usedMemory / 1024) + "K used"; big.setColor(Color.green); big.drawString(usedStr, x1 + 4, y1 + y2 - descent); // Calculate remaining size float ssH = ascent + descent; float remainingHeight = (float) (y2 - (ssH * 2) - 0.5f); float blockHeight = remainingHeight / 10; float blockWidth = 20.0f; float remainingWidth = (float) (x2 - blockWidth - 10); // .. Memory Free .. big.setColor(mfColor); int MemUsage = (int) (((totalMemory - usedMemory) / totalMemory) * 10); int i = 0; for (; i < MemUsage; i++) { mfRect.setRect(x1 + 5, (float) y1 + ssH + i * blockHeight, blockWidth, (float) blockHeight - 1); big.fill(mfRect); } // .. Memory Used .. big.setColor(Color.green); for (; i < 10; i++) { muRect.setRect(x1 + 5, (float) y1 + ssH + i * blockHeight, blockWidth, (float) blockHeight - 1); big.fill(muRect); } // .. Draw History Graph .. if (remainingWidth <= 30) remainingWidth = (float) 30; if (remainingHeight <= ssH) remainingHeight = (float) ssH; big.setColor(graphColor); int graphX = x1 + 30; int graphY = y1 + (int) ssH; int graphW = (int) remainingWidth; int graphH = (int) remainingHeight; graphOutlineRect.setRect(graphX, graphY, graphW, graphH); big.draw(graphOutlineRect); int graphRow = graphH / 10; // .. Draw row .. for (int j = graphY; j <= graphH + graphY; j += graphRow) { graphLine.setLine(graphX, j, graphX + graphW, j); big.draw(graphLine); } // .. Draw animated column movement .. int graphColumn = graphW / 15; if (columnInc == 0) { columnInc = graphColumn; } for (int j = graphX + columnInc; j < graphW + graphX; j += graphColumn) { graphLine.setLine(j, graphY, j, graphY + graphH); big.draw(graphLine); } --columnInc; // Plot memory usage by this memory pool. if (usedMem[npool] == null) { usedMem[npool] = new float[usageHistCount]; ptNum[npool] = 0; } // save memory usage history. usedMem[npool][ptNum[npool]] = usedMemory; big.setColor(Color.yellow); int w1; // width of memory usage history. if (ptNum[npool] > graphW) { w1 = graphW; } else { w1 = ptNum[npool]; } for (int j = graphX + graphW - w1, k = ptNum[npool] - w1; k < ptNum[npool]; k++, j++) { if (k != 0) { if (usedMem[npool][k] != usedMem[npool][k - 1]) { int h1 = (int) (graphY + graphH * ((totalMemory - usedMem[npool][k - 1]) / totalMemory)); int h2 = (int) (graphY + graphH * ((totalMemory - usedMem[npool][k]) / totalMemory)); big.drawLine(j - 1, h1, j, h2); } else { int h1 = (int) (graphY + graphH * ((totalMemory - usedMem[npool][k]) / totalMemory)); big.fillRect(j, h1, 1, 1); } } } if (ptNum[npool] + 2 == usedMem[npool].length) { // throw out oldest point for (int j = 1; j < ptNum[npool]; j++) { usedMem[npool][j - 1] = usedMem[npool][j]; } --ptNum[npool]; } else { ptNum[npool]++; } } public void start() { thread = new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.setName("MemoryMonitor"); thread.start(); } public synchronized void stop() { thread = null; notify(); } public void run() { Thread me = Thread.currentThread(); while (thread == me && !isShowing() || getSize().width == 0) { try { thread.sleep(500); } catch (InterruptedException e) { return; } } while (thread == me && isShowing()) { Dimension d = getSize(); if (d.width != w || d.height != h) { w = d.width; h = d.height; bimg = (BufferedImage) createImage(w, h); big = bimg.createGraphics(); big.setFont(font); FontMetrics fm = big.getFontMetrics(font); ascent = (int) fm.getAscent(); descent = (int) fm.getDescent(); } repaint(); try { thread.sleep(sleepAmount); } catch (InterruptedException e) { break; } if (MemoryMonitor.dateStampCB.isSelected()) { System.out.println(new Date().toString() + " " + usedStr); } } thread = null; } } // Test thread to consume memory static class Memeater extends ClassLoader implements Runnable { Object y[]; public Memeater() { } public void run() { y = new Object[10000000]; int k = 0; while (true) { if (k == 5000000) k = 0; y[k++] = new Object(); try { Thread.sleep(20); } catch (Exception x) { } // to consume perm gen storage try { // the classes are small so we load 10 at a time for (int i = 0; i < 10; i++) { loadNext(); } } catch (ClassNotFoundException x) { // ignore exception } } } Class loadNext() throws ClassNotFoundException { // public class TestNNNNNN extends java.lang.Object{ // public TestNNNNNN(); // Code: // 0: aload_0 // 1: invokespecial #1; //Method java/lang/Object."<init>":()V // 4: return // } int begin[] = { 0xca, 0xfe, 0xba, 0xbe, 0x00, 0x00, 0x00, 0x30, 0x00, 0x0a, 0x0a, 0x00, 0x03, 0x00, 0x07, 0x07, 0x00, 0x08, 0x07, 0x00, 0x09, 0x01, 0x00, 0x06, 0x3c, 0x69, 0x6e, 0x69, 0x74, 0x3e, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01, 0x00, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x0c, 0x00, 0x04, 0x00, 0x05, 0x01, 0x00, 0x0a, 0x54, 0x65, 0x73, 0x74 }; int end[] = { 0x01, 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00, 0x21, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x05, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x2a, 0xb7, 0x00, 0x01, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // TestNNNNNN String name = "Test" + Integer.toString(count++); byte value[]; try { value = name.substring(4).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException x) { throw new Error(); } // construct class file int len = begin.length + value.length + end.length; byte b[] = new byte[len]; int i, pos = 0; for (i = 0; i < begin.length; i++) { b[pos++] = (byte) begin[i]; } for (i = 0; i < value.length; i++) { b[pos++] = value[i]; } for (i = 0; i < end.length; i++) { b[pos++] = (byte) end[i]; } return defineClass(name, b, 0, b.length); } static int count = 100000; } public static void main(String s[]) { final MemoryMonitor demo = new MemoryMonitor(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } public void windowDeiconified(WindowEvent e) { demo.surf.start(); } public void windowIconified(WindowEvent e) { demo.surf.stop(); } }; JFrame f = new JFrame("MemoryMonitor"); f.addWindowListener(l); f.getContentPane().add("Center", demo); f.pack(); f.setSize(new Dimension(400, 500)); f.setVisible(true); demo.surf.start(); Thread thr = new Thread(new Memeater()); thr.start(); } }
运行结果:
发表评论
-
java Romdom例子
2011-06-16 16:41 1836random.netInt()如果括号里 ... -
java 内部类详解(转)
2011-06-01 15:47 4925Java 内部类 分四种:成员内部类、局部内部类、静态内部类和 ... -
Fibonacci数列计算+找出出现次数最多字符+不同数字的排列组合
2011-05-26 15:40 20571,斐波拉契数列的计算 package chapter9; ... -
java中的System类中的方法
2011-05-24 11:00 966public final class System exten ... -
java 界面swing之表格
2011-05-20 13:39 6487package othertest; import ja ... -
java的队列和栈的一些api
2011-05-16 11:31 1662类 Stack<E> java.lang.Obje ... -
JAVA 中一些api(字符字符串缓冲,URL类,Math类方法,正则表达式)
2011-05-12 10:36 1705CharBuffer字符缓冲区, StringBuffer字符 ... -
java applet 一个简单的例子(applet+html)
2011-05-09 16:49 4108java applet是一个类,其层次结构如下图: 类 JAp ... -
java 核心技术(数组(杨辉三角),散列码,对象拷贝,枚举类型,定时器)
2011-05-04 10:43 1515数组java中无多维数组,都是一维数组,多维数组可以看做是数组 ... -
设计模式总结
2011-04-26 16:50 838对于GoF总结的经典的23中设计模式,分为3类: (1)创建型 ... -
猜数字游戏
2011-04-12 17:27 1132package guessNumber; import ... -
Comparator实现排序
2011-04-01 14:13 8614在java.util包中有一个Collections类,里面实 ... -
21天学会java(含电子书下载)
2011-03-15 16:12 249921天学通java 比较基础 第一天 创建简单applicat ... -
理解浮点数存储
2011-03-15 09:44 961整体呈现 二进制浮 ... -
java.lang.UnsatisfiedLinkError解决办法
2011-03-10 16:59 1124实质上就是Eclipse下配置jdk,jre环境的问题 win ... -
java string,stringbuffer区别例子
2011-01-11 14:44 1335public class test_3 { public ... -
java定时器的使用
2011-01-11 09:20 1425有时需要在一定时间段后,执行某一个操作 java中现有的Ti ... -
对象简单克隆clone和引用(转)
2010-12-15 17:02 844对象克隆,返回和原对 ... -
java applet例子---图片像素处理
2010-12-07 17:01 1878package applet; import java. ... -
java applet例子---跟踪图片对象的加载
2010-12-07 16:56 1464用java.awt包中的MediaTracker跟踪一个Ima ...
相关推荐
VisualVM是一种集成了多个JDK命令行工具的可视化工具,它能为您提供强大的分析能力。所有这些都是免费的!它囊括的命令行工具包括jps,jstat,jmap,jinfo,jstack,JConsole,这些工具与JDK的标准版本是一致的。 jinfo:...
Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...
Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...
Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...
Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...
Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...
Java波浪文字,一个利用Java处理字符的实例,可以设置运动方向参数,显示文本的字符数组,高速文本颜色,显示字体的 FontMetrics对象,得到Graphics实例,得到Image实例,填充颜色数组数据,初始化颜色数组。...
java语言操作系统课程设计模拟进程管理系统源码 需求分析 实现n个进程并发运行;...针对需求5:为了能够及时的表征程序运行状态和提供良好的交互接口,可以利用Java.awt图形用户接口来编写一个动态的可视化交互界面。
在有状态SessionBean中,用累加器,以对话状态存储起来,创建EJB对象,并将当前的计数器初始化,调用每一个EJB对象的count()方法,保证Bean正常被激活和钝化,EJB对象是用完毕,从内存中清除…… Java Socket 聊天...
1) 每一个进程有一个PCB,其内容可以根据具体情况设定。 2) 可以在界面设定的互斥资源(包括两...6) 采用可视化界面,可在进程调度过程中随时暂停调度,查看当前进程的状态以及相应的阻塞队列 7) 具有一定的数据容错性
在启动时,可视化将显示数据集中提供的49,738个列表中的1,000个随机样本。 这样做是为了防止出现内存问题,以使应用程序不会因该数量的数据而崩溃,但仍可以代表所存储的信息。 美国主要城市的AirBnb列表上的数据...
在有状态SessionBean中,用累加器,以对话状态存储起来,创建EJB对象,并将当前的计数器初始化,调用每一个EJB对象的count()方法,保证Bean正常被激活和钝化,EJB对象是用完毕,从内存中清除…… Java Socket 聊天...
以计算机操作系统原理为指导,利用面向对象程序设计技术仿真 OS 内核的作业管理、 连续内存管理、页式虚存管理、进程同步与互斥、缓冲技术、磁盘管理和文件管理的 API 功 能,可视化显示操作系统工作过程,完成操作...
4、所有配置档仅在工具启动初始读取一次并缓存到内存中,因此,如果您是在工具运行 时修改的配置档,请重新启动本工具以使新的配置生效。并且,所有配置档的XML结构均 不能修改,只能修改其节点间的文本值或属性值,...
wgcloud是一款可视化的Linux运维监控工具,内置对系统的各维度监控,提供可视化的数据显示,让我们实时了解系统的运行状态。比如对CPU的指标监测、内存的监测、系统磁盘空间的监测,服务接口的监测等等。 WGCLOUD...
UI等entfrm-boot可视化开发平台使用说明:1、配置环境(jdk1.8、maven3.x、mysql5.6及以上、redis3.2及以上)2、创建数据库3、初始化sql脚本:entfrm.sql4、导入项目到IntelliJ IDE中5、修改配置文件entfrm-boot/...
(3)理解内存分配原理,特别是以页面为单位的虚拟内存分配方法。 要求:(1)经调试后程序能够正常运行。 (2)采用多进程或多线程方式运行,体现了请求分页存储管理页面Optimal、FIFO、LRU调度算法的关系。 (3)...
使用Echart加入了可视化数据,进行简单的可视化操作。使用了流加载对通知公告进行显示。 1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都...
包含鲜艳的GUI设计,内存分配可视化,指定(多个)进程前驱等重要功能! 实验具体要求 (1)设计一个抢占式优先权调度算法实现多处理机调度的程序,并且实现在可变分区管理方式下,采用首次适应算法实现主存空间的分配...