Tuesday 30 August 2011

How to change classes in the running java application?

There are a few possibilities:
  • Hot deploy - Application is redeployed by application servers after the update of code. Usually after a few redeploys application server has to be restated because of possible memory leaks.
  • HotSwap - Allowed since Java 1.4. We can change the methods' definitions in classes during debug session. We cannot change class fields or add new methods, constructors or classes.
  • OSGI - Allows us to change modules of application. It is faster then Hot deploy, but we need to design our application to be OSGI modular, which requires more expensive and more difficult development process.
  • Throwaway class loaders - Many frameworks use components that are loaded in separate class loaders.The whole class loader is reloaded after the change, e.g. Tapestry, Seam, ...
  • Use JRebel - a tool updating class definitions. JRebel operates on class loaders.

No comments: