I've read that implementing Externalizable provides faster
performance that Serializable, at least according to:
http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/index.html?page=5
>From my understanding, the primary benefit of Externalizable
is that when I write my marshalling methods, I do not have
to marshall the superclasses of my object (which Serializing
does automatically). Is that right?
However, suppose I have a simple class (whose superclass
is Object) and contains only an int, a String, and a byte array.
Since there is no superclass, implementing Externalizable
or Serializable should not make much of a difference in
terms of performance, no? Indeed, my cursory implementation
both ways shows little difference at all (and any differences
are within the boundaries of experimental error).
Stefan Schulz - 13 May 2006 21:22 GMT
That is the catch, why usually Externalizable is not used. If the
superclass is trivial anyway (Object or very similar), Marshalling it
via standard serialization does not add any significant overhead. On
the other hand, if it is non-trivial, it is usually not exactly easy to
serialize by hand, usually forcing you to break member protection by
means of reflection... in which case most of the performance advantage
disappears again.