In order to use the instrumentation features introduced in JDK 5, you can use the -javaagent
flag passed to the JVM. This will inject an instance of an Instrume
I think the simplest solution is to use the global properties object. Have pre-main store the instrumentation object as a global properties and then access it from everywhere (the properties object is the same in all class loaders):
[Edit: updated]
public class MyClass {
private static final String KEY = "my.instrumentation";
public static void premain(String options, Instrumentation inst) {
Properties props = System.getProperties();
if(props.get(KEY) == null)
props.put(KEY, inst);
}
public static Instrumentation getInstrumentation() {
return System.getProperties().get(KEY);
}
}