Java 线程 - 测试线程耗用堆内存

1.代码

package com.study.threadpool;

import java.util.concurrent.CountDownLatch;

public class ThreadDemo {
	public static void main(String[] args) {
		CountDownLatch cdl = new CountDownLatch(1);
		try {
			Thread.sleep(2000L);
		}catch(InterruptedException e)
		{
			e.printStackTrace();
		}
		for(int i=0;i<5000;i++)
		{
			new Thread(new Runnable() {
				public void run() {
					try {
						cdl.await();
					}catch(InterruptedException e) {
						e.printStackTrace();
					}
				}
			}).start();
			System.out.println("i = " + i);
		}
	}
}

2. java VisualVM工具

    用java VisualVM工具查看堆内存的耗用情况。

猜你喜欢

转载自blog.csdn.net/liyazhen2011/article/details/87915683