Merge pull request #7666 from macieg/bael-3192

BAEL-3192 | A guide to System.gc()
This commit is contained in:
Eric Martin 2019-09-08 14:04:39 -05:00 committed by GitHub
commit c2a9469856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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");
}
}
}
}