What really gets passed when you pass an object to a remote method?

image with no caption

If your remote method has an argument that’s an object type, the argument is passed as a full copy of the object itself!

For remote calls, Java passes objects by object copy, not reference copy.

A serialized copy of the object is shipped to the Remote object.

image with no caption

Getting the object argument from the client to the server

  1. Client invokes trainPet(myDog) on the stub, passing a copy of the reference to the Dog object.

    image with no caption
  2. The stub makes a serialized copy of the object and sends that copy over the wire to the skeleton.

    image with no caption

Unpacking (deserializing) the object on the server

  1. The skeleton deserializes the passed argument, creating a new Dog object in the Remote object’s heap.

    image with no caption
  2. The skeleton invokes the method on the Remote object, passing a plain old Java reference to the new Dog object.

    image with no caption

Get Head First EJB now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.