Created
July 11, 2013 20:13
-
-
Save batmat/5978810 to your computer and use it in GitHub Desktop.
Small code to be able to check a VM and the activated GC. Also useful to run a VM so that you have time to run VisualVM or something similar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.management.*; | |
public class WhichGC | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
int seconds = 60; | |
if(args.length>=1) | |
{ | |
seconds = Integer.parseInt(args[0]); | |
} | |
List<GarbageCollectorMXBean> l = ManagementFactory.getGarbageCollectorMXBeans(); | |
for(GarbageCollectorMXBean b : l) { | |
System.out.println(b.getName()); | |
} | |
System.out.printf("Let's now wait for %d seconds as requested so that you can run "+ | |
"VisualVM or an equivalent to check the running VM\n", seconds); | |
Thread.sleep(seconds*1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment