BAEL-7592: Improved example for GC overhead limit exceeded (#15989)
This commit is contained in:
parent
666c81960b
commit
c96669b39b
|
@ -1,19 +1,21 @@
|
||||||
package com.baeldung.outofmemoryerror;
|
package com.baeldung.outofmemoryerror;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class OutOfMemoryGCLimitExceed {
|
public class OutOfMemoryGCLimitExceed {
|
||||||
public static void addRandomDataToMap() {
|
|
||||||
Map<Integer, String> dataMap = new HashMap<>();
|
public static final Random RANDOM = new Random();
|
||||||
Random r = new Random();
|
|
||||||
|
public static void addRandomDataToList() {
|
||||||
|
List<String> dataList = new LinkedList<>();
|
||||||
while (true) {
|
while (true) {
|
||||||
dataMap.put(r.nextInt(), String.valueOf(r.nextInt()));
|
dataList.add(String.valueOf(RANDOM.nextInt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
OutOfMemoryGCLimitExceed.addRandomDataToMap();
|
OutOfMemoryGCLimitExceed.addRandomDataToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue