1 2 3 4 5 6 7 8 9 10 11 12 13 | String s1 = "小金子(aub)" ; String s2 = "小金子(aub)" ; String s3 = "小金子" + "(aub)" ; String s4 = new String( "小金子(aub)" ); String s5 = "小金子" + new String( "(aub)" ); String s6 = s4.intern(); System.out.println( "s1 == s2: " + (s1 == s2)); //true; System.out.println( "s1 == s3: " + (s1 == s3)); //true; System.out.println( "s2 == s3: " + (s2 == s3)); //true; System.out.println( "s1 == s4: " + (s1 == s4)); //false; System.out.println( "s1 == s5: " + (s1 == s5)); //false; System.out.println( "s4 == s5: " + (s4 == s5)); //false; System.out.println( "s1 == s6: " + (s1 == s6)); //true; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class JvmStackOOM {
private int stackLength = 1 ;
public void execute() {
try {
stackLeak();
} catch (Throwable e) {
System.out.println( "stackLength : " + stackLength);
e.printStackTrace();
}
}
private void stackLeak() {
stackLength++;
stackLeak();
} } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public class JvmRuntimeConstantPoolOOM {
private int runtimeConstantCount = 1 ;
public void execute() {
try {
runtimeConstantLeak();
} catch (Throwable e) {
System.out.println( "runtimeConstantCount : " + runtimeConstantCount);
e.printStackTrace();
}
}
private void runtimeConstantLeak() {
List<String> list = new ArrayList<String>();
while ( true ) {
list.add(String.valueOf(runtimeConstantCount++).intern());
}
} } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class JvmHeapOOM {
private int bojectCount = 1 ;
public void execute() {
try {
heapLeak();
} catch (Throwable e) {
System.out.println( "bojectCount : " + bojectCount);
e.printStackTrace();
}
}
private void heapLeak() {
List<OOMObject> list = new ArrayList<OOMObject>();
while ( true ) {
list.add( new OOMObject());
bojectCount++;
}
}
private class OOMObject {
} } |