diff --git a/core-java-modules/core-java-jvm/src/main/java/com/baeldung/systemgc/DemoApplication.java b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/systemgc/DemoApplication.java new file mode 100644 index 0000000000..8bca55c5f0 --- /dev/null +++ b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/systemgc/DemoApplication.java @@ -0,0 +1,33 @@ +package com.baeldung.systemgc; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +import static java.util.UUID.randomUUID; + +public class DemoApplication { + + private static final Map cache = new HashMap(); + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + while (scanner.hasNext()) { + final String next = scanner.next(); + if ("fill".equals(next)) { + for (int i = 0; i < 1000000; i++) { + cache.put(randomUUID().toString(), randomUUID().toString()); + } + } else if ("invalidate".equals(next)) { + cache.clear(); + } else if ("gc".equals(next)) { + System.gc(); + } else if ("exit".equals(next)) { + System.exit(0); + } else { + System.out.println("unknown"); + } + } + } +} \ No newline at end of file