Skip to content

Commit 53ae0a7

Browse files
author
deleiguo
committed
update
1 parent 70dcde1 commit 53ae0a7

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

source/java/interview/delei-interview-java-core/src/main/java/cn/delei/java/JVMTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package cn.delei.java;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.stream.IntStream;
46

57
public class JVMTest {
68

7-
public static void main(String[] args) {
9+
public static void main(String[] args) throws Exception {
810
//CMSTest();
9-
G1Test();
11+
//G1Test();
12+
//stackOverFlow();
13+
//outOfMemory();
1014
}
1115

1216
static void CMSTest() {
@@ -19,6 +23,20 @@ static void G1Test() {
1923
test();
2024
}
2125

26+
static void outOfMemory() {
27+
// -Xms1M -Xmx10M
28+
List<JVMTest> data = new ArrayList<>();
29+
//无限创建对象,在堆中
30+
while (true) {
31+
data.add(new JVMTest());
32+
}
33+
}
34+
35+
static void stackOverflow() {
36+
// -Xms1M -Xmx10M -Xss1M
37+
stackOverflow();
38+
}
39+
2240
static void test() {
2341
int size = 1024 * 1024;
2442
IntStream.range(0, 11).forEach(e -> {

source/java/interview/delei-interview-java-core/src/main/java/cn/delei/java/util/HashMapDemo.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cn.delei.java.util;
22

33
import cn.delei.util.HashCodeUtil;
4+
import cn.delei.util.PrintUtil;
45

56
import java.lang.reflect.Field;
67
import java.lang.reflect.Method;
@@ -17,8 +18,8 @@ public class HashMapDemo {
1718
public static HashMap<String, String> hashMap;
1819

1920
public static void main(String[] args) {
20-
//opera();
21-
calcInitCapacity();
21+
opera();
22+
// calcInitCapacity();
2223
}
2324

2425
/**
@@ -28,6 +29,7 @@ static void opera() {
2829
try {
2930
int capacity = 7;
3031
hashMap = new HashMap();
32+
PrintUtil.printDivider("反射获取内部变量值");
3133
// 使用反射
3234
Class mapClass = hashMap.getClass();
3335
Field tableField = mapClass.getDeclaredField("table");
@@ -48,7 +50,9 @@ static void opera() {
4850
, thresholdField.get(hashMap), hashMap.size());
4951
}
5052
// put 相同 hashcode 的 key
51-
List<String> hashSting = HashCodeUtil.generateN(11);
53+
PrintUtil.printDivider("put 相同 hashcode 的 key");
54+
hashMap = new HashMap();
55+
List<String> hashSting = HashCodeUtil.generateN(5);
5256
int h = hashSting.get(0).hashCode();
5357
int hash = h ^ (h >>> 16);
5458
System.out.println("Hashcode:" + hash);

0 commit comments

Comments
 (0)