Skip to content

Instantly share code, notes, and snippets.

@batmat
Created July 11, 2013 20:13
Show Gist options
  • Save batmat/5978810 to your computer and use it in GitHub Desktop.
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.
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