RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Take Control of Class Loading in Java  : Page 4

By building a classloading component container framework that isolates Java class loading to a specified jar file, you can be confident that the runtime will load the component versions you expect.

Loading Specific Class Versions
Now, you can use the container and restricted classloader to load components containing versioned classes from specified archives.

Listing 2 shows how to instantiate instances of the component container and initialize them with the names of the configuration files for two different versions of a HelloWorld component. Each component version is then loaded and instantiated using the createComponent method of the ComponentContainer class.

Figure 3. Component Sequence: The figure shows the sequence the component container framework follows to create a component.
Calls to each instantiated component object produce results from the expected versions of each component.

The sequence diagram in Figure 3 illustrates the steps taken by the framework to load and create a component:

Notice that calls to the RestrictedURLClassLoader class terminate before reaching an instance of the default classloader; thereby restricting class-searching to the URLs supplied to the RestrictedURLClassLoader instance.

So, you've seen how to build a class loading component container framework that facilitates a self-contained context in which to define, version, and create Java components. Exploiting Java's class loading capabilities in this manner restricts class-loading to specified locations, leting you load different versions of classes simultaneously—both created and used in the same running JVM.

Jeff Hanson has more than 18 years of experience in the software industry. He has worked as senior engineer for the Windows OpenDoc port and as lead architect for the Route 66 framework at Novell. He is currently Chief Architect for eReinsure, which specializes in providing frameworks and platforms for J2EE-based reinsurance systems. Jeff has also authored numerous articles and books.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date