Java - Hot Deployment

I recently read a book on Erlang that has a hot deployment feature. Deployment can be performed without lowering the system. All existing requests will be processed by the old version of the code, and the new request after deployment will be served by the new code. In this case, both versions of the code available at runtime until all old queries are used. Is there any approach in Java where we can store 2 versions of jar files? Are these applications / web servers supported?

+4
source share
5 answers

There are many ways to achieve a hot deployment in the Java world, so you probably need a slightly more specific fight for your context and what you are trying to achieve.

Here are some good examples / options:

  • OSGi is a general-purpose system that supports hot deployment
  • Clojure is a dynamic JVM language that provides a lot of interactivity at runtime. Clojure is often used for live coding - almost anything can be hot-swapped and redefined at runtime. Clojure is a functional language with a strong emphasis on immutability and concurrency, so in a sense it has some interesting similarities with Erlang. Clojure has some very good web frameworks, such as Noir , which are suitable for hot swapping srever web code.
  • The Play Framework is designed to include hot-swap code to improve performance (to avoid restarting the web server). May be relevant if you are looking primarily for hot swappable web applications.
  • Most Java application servers, such as JBoss , support some form of hot swap for web applications.
+1
source

If you intend to speed up development, then JRebel is a tool for this purpose. However, I would not recommend using it to fix a production system.

JRebel detects when the class file has been modified and reloads it into the running application server without discarding any old state. This is much faster than what most operator applications do when redistributing an entire war / ear where the entire initialization process should be repeated.

+4
source

The only reason for hot updates in the production application is to ensure zero downtime for users.

LiveRebel (based on JRebel ) is a tool that can be used, for example, in conjunction with Jenkins. It can perform secure hotpatching as well as restart restart while disconnecting sessions on the production cluster.

+2
source

Technically, you CAN do it yourself. Although, I would not recommend it, as it can quickly get complicated. But the idea is that you can create a ClassLoader and load a new version of your class. Then make sure your executable is aware of the new ClassLoader.

I would recommend using JBoss and redistributing your banks and wars. Nice and simple for the most part.

In any case, you will be convinced that you do not have memory leaks, because after several redistributions you will leave the PermGen space.

+1
source

Add RelProxy to your toolbox, RelProxy is a reload of the hot class for Java (and Groovy) to improve development even for production, with only one significant limitation, reloading is possible only in a subset of your code.

0
source

Source: https://habr.com/ru/post/1402469/


All Articles