Sunday, June 1, 2008

Make a class available to all apps on an Apps Server


Question: How would you make a single class available to all applications on an Application Server? What are the advantages and disadvantages of this approach?

Answer: Simply by getting the class loaded by a top-level Classloader. For example, if you want to make an application specific class available to all the applications, you just need to add that class to the CLASSPATH of your application server. All the classes of the CLASSPATH are loaded by the time Java-supplied Application Classloader transfers the control to the application specific Apps Server supplied classloaders and hence every class, which is a part of the CLASSPATH will be available to all the application specific classloaders.

Advantages/Disadvantages of this approach

The obvious advantage of this approach is that you don't need to load the same class more than once, but it comes with at least two disadvantages as well, which are:-

  • You can not unload this class as it would be loaded by a Java-supplied classloader, which doesn't have the capability of unloading a loaded class unlike the Application Server supplied classloaders which have this capability as well.
  • If you require to modify this class then you will need to restart the server to get the changes reflected as Java-supplied classloders don't have the capability of re-loading the classes unlike Apps Server supplied classloaders.



Share/Save/Bookmark


No comments: