O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How Dynamic Classloading Works

In Chapter 10, while discussing how RMI customizes the serialization algorithm, I said:

ObjectOutputStream calls annotateClass( ) when it writes out class descriptions. Annotations are used to provide extra information about a class that comes from the serialization mechanism and not from the class itself. The basic serialization mechanism has no real need for annotations; most of the information about a given class is already stored in the stream...

RMI, on the other hand, uses annotations to record codebase information. That is, RMI, in addition to recording the class descriptions, also records information about the location from which it loaded the class’s bytecode.

These paragraphs, which may have seemed opaque before, should now make more sense. RMI’s dynamic classloading is based on two ideas:

  • If an object is serialized and sent over the wire, the required class definitions might not be available on the other side.

  • Automatically including URLs from which classes can be downloaded inside serialized objects allows special-purpose classloaders, such as the URLClassLoader class, to automatically load classes from over the wire when they’re needed to deserialize an object.

The basic algorithm, which is built into RMI’s deserialization mechanism, works as follows:

  1. An instance is sent over the wire. As part of the serialized information about the instance, all the related class definitions are also sent over the wire (including the definitions of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required