Java: Performance Issue with Serialization

Java serialization allows us to marshal and unmarshal objects. It is a mechanism automatically, at runtime, converts class objects into metadata so instances can be serialized with the least amount of programmer work.

In some of my Java applications, RMI is used quite frequently. Serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments in a method invocation from a client to a server or as return values from a method invocation. In this case, objects are marshalled and unmarshalled a lot between the RMI client and server. Serialization is slow especially for large object since

To turn off serialization on a certain field of an object, I tag that field of the class of our object with the Java’s “transient” keyword. This, to low-level parts of the Java virtual machine, is an indication that the transient variable is not part of the persistent state of an object.

E.g.

public class MyClass implements Serializable 
{
  private String saveMe;
  private transient String dontSaveMe;
}


Trackback URL

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)