184.108.40.206. Runtime classloading models
Another key consideration when deploying applications is the classloading model used by
the application server. Typically, a J2EE application server runs within a parent Java
virtual machine, and that parent JVM may spawn other JVMs or non-Java processes to
run specific runtime elements (messaging services, directory services, etc.). Within the
application server's JVM, the management of classloaders can be done in a variety of ways.
The most simplistic approach would be to have all applications share the same classloader.
In a multiple application scenario, this is usually not desirable since various applications,
or even different versions of the same application, may depend on different versions of
Figure 2-3. Deployed application
libraries and classes, which would cause conflicts in a single-classloader situation (the first
version of a class loaded at runtime would be used by all applications in the server). If an
application server runs all applications within the same classloader, then you may find
yourself forced to run multiple server instances in order to run each application with the
proper versions of libraries and classes.
A more realistic runtime model would be to assign a separate classloader to each deployed
application. This allows each application to load its own versions of specific classes,
independent of other applications. Assuming that the server is using the standard Java
classloader implementation, each application classloader would be a child of the server's
main classloader, so any libraries that you truly want to share across all applications (i.e.,
the same version used by all applications) will be loaded by the main server at startup. This
is typically done by either adjusting the server's startup classpath or putting the shared
libraries in a special library directory.
Some application servers impose a single classloading scheme on deployed applications,
while others allow you to configure the classloading scheme at a server or an application
level. It's important to understand the classloading schemes supported by your application
server and to adjust these settings if needed.