File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
source/java/interview/delei-interview-java-core/src/main/java/cn/delei/java Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change 1
1
package cn .delei .java ;
2
2
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
3
5
import java .util .stream .IntStream ;
4
6
5
7
public class JVMTest {
6
8
7
- public static void main (String [] args ) {
9
+ public static void main (String [] args ) throws Exception {
8
10
//CMSTest();
9
- G1Test ();
11
+ //G1Test();
12
+ //stackOverFlow();
13
+ //outOfMemory();
10
14
}
11
15
12
16
static void CMSTest () {
@@ -19,6 +23,20 @@ static void G1Test() {
19
23
test ();
20
24
}
21
25
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
+
22
40
static void test () {
23
41
int size = 1024 * 1024 ;
24
42
IntStream .range (0 , 11 ).forEach (e -> {
Original file line number Diff line number Diff line change 1
1
package cn .delei .java .util ;
2
2
3
3
import cn .delei .util .HashCodeUtil ;
4
+ import cn .delei .util .PrintUtil ;
4
5
5
6
import java .lang .reflect .Field ;
6
7
import java .lang .reflect .Method ;
@@ -17,8 +18,8 @@ public class HashMapDemo {
17
18
public static HashMap <String , String > hashMap ;
18
19
19
20
public static void main (String [] args ) {
20
- // opera();
21
- calcInitCapacity ();
21
+ opera ();
22
+ // calcInitCapacity();
22
23
}
23
24
24
25
/**
@@ -28,6 +29,7 @@ static void opera() {
28
29
try {
29
30
int capacity = 7 ;
30
31
hashMap = new HashMap ();
32
+ PrintUtil .printDivider ("反射获取内部变量值" );
31
33
// 使用反射
32
34
Class mapClass = hashMap .getClass ();
33
35
Field tableField = mapClass .getDeclaredField ("table" );
@@ -48,7 +50,9 @@ static void opera() {
48
50
, thresholdField .get (hashMap ), hashMap .size ());
49
51
}
50
52
// 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 );
52
56
int h = hashSting .get (0 ).hashCode ();
53
57
int hash = h ^ (h >>> 16 );
54
58
System .out .println ("Hashcode:" + hash );
You can’t perform that action at this time.
0 commit comments