2015/09/06 09:02

## redefinition对应Instrumentation.redefineClasses()能够实现类的热替换，但遗憾的是功能很有限。

 1 2 3 4 The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the  signatures of methods, or change inheritance.  These restrictions maybe be lifted in future versions.

 1 2 3 4 5 6 7 Spring Loaded is a JVM agent  for reloading  class file changes whilst a JVM is running.  It transforms classes at loadtime to make them amenable to later reloading.  Unlike  'hot code replace' which only allows simple changes once a JVM is running  (e.g. changes to method bodies), Spring Loaded allows you to  add/modify/delete methods/fields/constructors.  The annotations on types/methods/fields/constructors  can also be modified and it is possible to add/remove/change values in  enum types.

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 package test;   import demo.A;   public class TestPreMain {        // -javaagent:springloaded-1.2.0.RELEASE.jar -noverify      public static void main(String[] args)  throws Exception      {            A a =  new A();            while ( true )          {              a.say();              Thread.sleep( 3000 );          }      } }

 1 -javaagent:springloaded- 1.2 . 0 .RELEASE.jar -noverify

 1 set JAVA_OPTS=-javaagent:springloaded- 1.2 . 0 .RELEASE.jar -noverify

0
0 收藏

0 评论
0 收藏
0