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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.