使JAVA堆栈溢出的方法

1. 使栈溢出

public class Test{
	public static void main(String[] args){
		System.out.println("OK");
		out(1);
	}
	
	private static void out(int i){
		System.out.println(i);
		out(++i);
	}
}

运行命令:

java -Xss1m Test

2. 使堆溢出

public class Test{
	public static void main(String[] args){
		byte[] b = new byte[1024 * 1024 * 1024 * 1];
		System.out.println("OK");
	}	
}

运行命令:

java -Xmx50m Test

其它命令

查看进程Id

jps

查看进程使用的堆大小:

jmap -heap [pid]

猜你喜欢

转载自oracle-api.iteye.com/blog/2357817
今日推荐