First, create with JDK 7 this Java Project in Eclipse:
Then, install the VisualVM GC plugin. Run the GCTestMain main, using these JVM arguments: -verbose:gc -Xms256m -Xmx256m. THen connect with JConsole and with VisualVM (I downloaded the one from the main website.... beware that there can be issues on connection when running on Windows when the username has uppercase characters (Windows sucks, don't forget).
package com.pierre.gctests;
import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
public class GCTestMain {
private static void init() throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
MBeanServer mbs = null;
mbs = ManagementFactory.getPlatformMBeanServer();
GCTestAgent agent = new GCTestAgent();
ObjectName agentName;
agentName = new ObjectName("PVTests:name=GCTestAgent");
mbs.registerMBean(agent, agentName);
}
public static void main(String[] args) throws Exception {
init();
for (;;) {
Thread.sleep(1000);
}
}
}
package com.pierre.gctests;
public interface GCTestAgentMBean {
void newThread(String threadName);
void newCollectableObject(int size);
void newLeakedObject(int size);
void clearLeaked();
void cpuIntensiveOperation(int iterations);
}
package com.pierre.gctests;
import java.util.ArrayList;
import java.util.Date;
public class GCTestAgent implements GCTestAgentMBean, Runnable {
ArrayList
Then, install the VisualVM GC plugin. Run the GCTestMain main, using these JVM arguments: -verbose:gc -Xms256m -Xmx256m. THen connect with JConsole and with VisualVM (I downloaded the one from the main website.... beware that there can be issues on connection when running on Windows when the username has uppercase characters (Windows sucks, don't forget).