14

What is JVM Hot Swapping?

Many definitions say that this feature allows code to updated on the fly during de-bugging.

And a few restrictions such as hot swapping is limited to updating method bodies only, and trying to add methods and fields to classes would not succeed.

Can anyone explain this with code.

gautam vegeta
  • 653
  • 6
  • 13
  • 28
  • You typically do it from your IDE while debugging/running your code from the IDE. You make changes to a part of your code, hot swap it, and resume running / debugging with the new code without having to recompile or restart your application. – assylias Nov 26 '12 at 12:25

1 Answers1

16

All it means is that you can make certain changes to your code while in the middle of a debugging session, and have those changes take effect immediately, without having to restart the application.

This can be a very handy feature in some circumstances. However, you're typically restricted in what kinds of code changes can be hotswapped into a running application. The exact nature of the restrictions depends on your toolchain.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • When not using JRebel, any kind of change to the class structure including a method signature cannot be hot-swapped. Basically only when changing the body of a method it works. – Gimby Nov 26 '12 at 12:35
  • 1
    So does this mean that if a certain code change comes into effect without re-deploying the application then it means that that portion of the code has been hot-swapped. – gautam vegeta Nov 26 '12 at 12:43
  • For hot-swapping to occur should the code be compiled or the hot sapping feature itself compiles the code and hot-swaps. – gautam vegeta Nov 26 '12 at 13:15