Externalizable vs. Serializable

D

Digital Puer

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).
 
S

Stefan Schulz

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top