BAEL-3192 | A guide to System.gc()

This commit is contained in:
Maciej Andrearczyk 2019-08-27 22:21:37 +02:00 committed by Maciej Andrearczyk
parent 9d7d7b4dde
commit d68530b539
1 changed files with 33 additions and 0 deletions

View File

@ -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<String, String> cache = new HashMap<String, String>();
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");
}
}
}
}