Pages

Friday, February 12, 2016

HotSwap vs hot deploy

It is the year 2016 and one still has to explain that HotSwap and hot deploy in Java IDEs is not the same thing.


Stackoverflow is full of questions about avoiding restarts of Java applications. So of the answers suggests that “Eclipse can update code without restarting the application” or “IntelliJ IDEA can hot update running applications” or “NetBeans automatically updates running code in debugger”. But the ultimate solution for this problem is JRebel, of course.

UPD: You can also read about various solutions to the redeployment problem in my Stackoverflow answer.

One fundamental thing that people don’t understand is that it is not even the capability of an IDE to be able to update applications. The IDE is just a medium -- it only triggers the update, and then the runtime environment is the one responsible for updating the code.

Repeat after me

HotSwap and Hot deploy is not the same thing!

What is HotSwap?

HotSwap (тм) is the technology in HotSpot JVM that is tailored at updating class definitions at runtime. Most importantly, "HotSwap adds functionality to the Java Platform Debugger Architecture (JPDA) to allow a class to be updated while under the control of a debugger”.

So when it comes to IDEs, once an application is started in a debug mode, the IDE can trigger class redefinition in a running JVM by utilizing JPDA.

If you are interested in the intimate details of HotSwap, read the “Safe class and data evolution in large and long-lived java applications” paper by M. Dmitriev.

It is important to understand the limitations of HotSwap: it is limited only to updating statements of code inside methods. Can’t change method signatures, can’t add new methods, fields, etc. Some JVM implementations are able to do a bit more. For instance, with IBM J9 JVM it is possible to add new methods to an existing class. Nevertheless, HotSwap capabilities are minimal. A JEP for enhanced class redefinition has been submitted long ago, and even a research project was sponsored by Oracle, but no further progress was made.

The bottom line here is that HotSwap is not a feature of an IDE, it is the ability of a JVM that you use.

What is hot deploy?

Hot deploy is the ability of application container to automatically deploy (web) applications at the startup. Obviously, the same feature can be applied to re-deploy the applications without restarting the JVM process.

Hot deploy is not a feature in any of the IDEs either. IDEs can only trigger (re)deployment of an application by either copying the artefacts to a correct location, or by using hooks if provided by the application server. So this is totally application server specific - this is what server adapters are for! It requires the IDE to be aware of the application server specifics, hence some people affiliate this functionality to their IDE.

Redeploying the application drops its state. Sometimes, application server can serialize/deserialize HTTP session state, but that's about it, not more. It can't preserve the state of the structures inside the application; internal caches have to be warmed up; framework internals have to be reinitialized, etc. The process is time consuming.

Application servers rely on class loader magic to redeploy applications. You can read about it in details in ZeroTurnaround’s blog.

Summary

Make sure you use the terms correctly -- 'HotSwap' and 'hot deploy' is not the same thing! You may other terms, like 'hot update' -- then make sure to ask, what does the person actually means by this, because the devil is in the details.

Disqus for Code Impossible