一、测试代码测试
- public class JProfilerMemMain {
-
- private List<Integer> arr2 = null;
-
-
- public void test2() {
- arr2 = test();
- }
-
-
- public List<Integer> test() {
- List<Integer> arr = new ArrayList<Integer>();
- for (int i = 0; i < 200000; i++) {
- arr.add(i * 100);
- }
- return arr;
- }
-
- public static void main(String[] args) throws IOException {
- JProfilerMemMain jp = new JProfilerMemMain();
- for (int i = 1; i <= 10; i++) {
- jp.test2();
-
- }
- System.out.println("程序执行完毕");
-
- char ch = ' ';
- while (ch != 'n') {
- ch = ch;
- }
- }
-
二、查看步骤 spa
启动JProfiler,等程序打印出"程序执行完毕" 后查看以下,Integer对象有800264个线程

点击菜单上的按钮"Run GC" 执行垃圾回收后查看以下,Integer对象还有200270个orm

说明未彻底释放数据,查看对象在堆的快照对象

从如下视图能够看到该对象的arr2属性有数据未释放内存
①Heap Walker->Biggest Objectsstring

②Heap Walker->References,JProfilerMemMain对象自身占用空间16bytes,引用其余对象占空间4288kBit

③Heap Walker->Data,中arr2属性有数据占用空间io

一、测试代码class
- package com.yyh.base.jprofile;
-
- public class DeadlockMain implements Runnable {
- boolean flag;
- static Object o1 = new Object();
- static Object o2 = new Object();
-
- public void run() {
- System.out.println(flag);
- if (flag) {
- synchronized (o1) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- synchronized (o2) {
- System.out.println("AAA");
- }
- }
-
- } else {
- synchronized (o2) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- synchronized (o1) {
- System.out.println("BBB");
- }
- }
-
- }
-
- }
-
- public static void main(String[] args) {
- DeadlockMain aaa = new DeadlockMain();
- DeadlockMain bbb = new DeadlockMain();
- aaa.flag = true;
- bbb.flag = false;
- Thread thA = new Thread(aaa);
- thA.setName("线程AAA");
-
- Thread thB = new Thread(bbb);
- thB.setName("线程BB");
-
- thA.start();
- thB.start();
- }
- }
二、查看步骤
启动JProfiler,等程序执行一段时间后查看以下,线程AAA和线程BB出现阻塞

查看Thread Views-> Thread Monitor
①线程AAA的调用方的类和方法

②线程BB的调用方的类和方法

查看Thread Views-> Thread Dumps
①线程AAA的阻塞的代码位置

②线程BB的阻塞的代码位置
