How can I use java.lang.instrument in an Eclipse RCP application?

前端 未结 1 1000
日久生厌
日久生厌 2020-12-21 01:36

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

相关标签:
1条回答
  • 2020-12-21 01:42

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题