Update Java code during runtime

后端 未结 3 426
死守一世寂寞
死守一世寂寞 2021-01-04 23:08

about a year ago I stumbled across a nice feature in Java that I cannot for the life of me find again.

Through some magic interface it was apparently possible to dec

3条回答
  •  鱼传尺愫
    2021-01-04 23:44

    The HotSwap technology was added to Java 1.4 and enable class file replacement at run-time. The feature is provide through the redefineClasses method of the instrumentation package. I think you can also do that through the JPDA interface.

    Here is also a reference to what I believe is the research paper that describe the HotSwap mechanism first:

    • Towards Flexible and Safe Technology for Runtime Evolution of Java Language Applications

    Otherwise you can use Classloader, as the other mentionned, but it only provides dynamic class loading, not replacement. The same class loaded twice will be considered as two different types. Combined with interface and/or a bit of reflection, it can however provide ways to update the application at run-time.

    Here is a reference to an awesome paper about class loader, and there usage:

    • Dynamic Class Loading in the Java Virtual Machine

    I won't expand on whether this is good or bad, because it was not your question, but I think it's great to have support for run-time software evolution -- too bad that JSR-117 never made it!

提交回复
热议问题