Recently, I was reading book about Erlang which has hot deployment feature. The deployment can be done without bringing the system down. All the existing requests will be handled by old version of code and all the new request after deployment will be served by the new code. In these case, both the versions of code available in runtime for sometime till all the old requests are served. Is there any approach in Java where we can keep 2 versions of jar files? Is there any app/web servers support this?
-
I believe Tomcat, for 1, supports this, although I do not know if it is advised in a production environment. – cdeszaq Mar 20 '12 at 15:14
-
You can do this with most Java application servers such as Glassfish/Websphere/Weblogic in a clustered environment. – Jonathan S. Fisher Mar 20 '12 at 15:15
-
1JBoss also supports this. Whether it's advisable however is debatable. – mcfinnigan Mar 20 '12 at 15:16
5 Answers
If your intention is to speed up development then JRebel is a tool for just this purpose. I wouldn't however recommend to use it to patch a production system.
JRebel detects whenever a class file has changed and reloads it into the running appserver without throwing any old state away. This is much faster compared to what most appservers do when redeploying a whole war/ear where the whole initialization process must rerun.

- 173
- 5
-
-
JRebel is a development tool. For production, there's LiveRebel (http://liverebel.com) – Anton Arhipov May 05 '12 at 18:29
There are many ways to achieve hot deployment in the Java world, so you'll probably need to be a bit more specific bout your context and what you are trying to achieve.
Here are some good leads / options to consider:
- OSGi is a general purpose module system that supports hot deployment
- Clojure is a dynamic JVM language that enables a lot of runtime interactivity. Clojure is often used for "live coding" - pretty much anything can be hot-swapped and redefined at runtime. Clojure is a functional language with a strong emphasis on immutability and concurrency, so in some ways has some interesting similarities with Erlang. Clojure has some very nice web frameworks like Noir that are suitable for hot swapping web srever code.
- The Play Framework is designed to enable hot swapping code for productivity reasons (avoiding web server restarts). Might be relevant if you are looking primarily at hot-swapping web applications.
- Most Java applicatio servers such as JBoss support some form of hot-swapping for web applications.

- 105,238
- 25
- 256
- 415
The only reason for hot updates on production application is the aim to provide zero downtime to the users.
LiveRebel (based on JRebel) is the tool that could be used in conjunction with Jenkins, for instance. It can do safe hotpatching as well as rolling restarts while draining the sessions on the production cluster.

- 6,479
- 1
- 35
- 43
Technically, you CAN do this yourself. Although, I wouldn't recommend it since it can get complicated quickly. But the idea is that you can create a ClassLoader and load your new version of your class. Then make sure that your executing code knows about the new ClassLoader.
I would recommend just using JBoss and redeploying your jars and wars. Nice and simple for the most part.
In either case, you have make sure you don't have any memory leaks because You'll run out of PermGen space after a few redeployments.

- 1,103
- 6
- 10