I'm interested on knowing when the Garbage Collector starts & ends during the execution of a Java application. I've been reading the JVMTI documentation which provides this kind of information (http://docs.oracle.com/javase/7/docs/platform/jvmti/jvmti.html). I've also found an example on how to use these events (e.g., http://code.metager.de/source/xref/openjdk/jdk8/jdk/src/share/demo/jvmti/gctest/gctest.c).
Note that the example creates a new thread (which is executed whenever JVMTI_EVENT_VM_INIT occurs - the callback is set in lines 173, 178 and 179) and it RunAgentThread (lines 120-121) receives this newly created thread. I've modified it to not create the thread (i.e. commented lines 173, 178 and 179) and the agent seems to work in the same way. So, is it necessary to create this agent thread to monitor the GC activity? And if so, why?