128 WebSphere eXtreme Scale Best Practices for Operation and Management
Dealing with efficient serialization will not greatly complicate the programming model of an
application or corporate application standard. The modest skill that is needed to write the two
Externalizable methods can be learned quickly and only requires simple Java skill to begin.
The efficient serialization logic can be put in the Externalizable methods for use with other
serialization-using functions, such as HTTPSession replication. This efficient serialization
logic can be put in the same Externalizable methods in the objects being stored in
WebSphere eXtreme Scale, in a separate class implementing the WebSphere eXtreme Scale
ObjectTransformer interface and attached to the WebSphere eXtreme Scale map, or split
between them. The efficiency that you can gain is the same for any of these three (except as
mentioned in the next paragraph).
The following article provides a good description of how serialization in Java works:
򐂰 “The Java serialization algorithm revealed”
This article does not mention Externalizable specifically, but it does give you an idea of the
overhead that you can avoid by using both Externalizable and the WebSphere eXtreme Scale
ObjectTransformer interface.
The following article describes Serialization more broadly, including Externalizable (note the
paragraph about “Performance Considerations” near the end, which recommends that you
“write your own protocol” to achieve the best performance, which is what we have explained
how to do here):
򐂰 “Discover the secrets of the Java Serialization API”
It is not always necessary to have efficient serialization, although usually it is. Efficient
serialization makes the operation of WebSphere eXtreme Scale faster for that object. Gets
are faster, because there is less data to flow over the wire from the WebSphere eXtreme
Scale container to the client application. Puts are faster for the reverse flow from the client to
the container and the replica container. In both cases, far less CPU is used when the logic is
efficient. However, if the logic using the object is not performance-sensitive (if it is used
infrequently and if getting the object is one small part of an already long operation), you might
not have to bother. Performance testing will let you know.
Existing packages for improved serialization with less writing code
There are packages on the Internet that can help you improve serialization. WSSUtils also
includes serialization support. Neither of these packages is as efficient as writing your own
code, but they require substantially less coding, because they both use modern introspection.
You merely have to assert in one line that you want a given class to have serialization done.
We have not tested either of these packages as of the time of publishing this book.
6.4.2 Implementing the Externalizable interface
When you implement the Externalizable interface, you are then required by the interface
contract to provide implementations of the readExternal(java.io.ObjectInput in) and the
writeExternal(java.io.ObjectOutput out) methods. You get complete control over the
serialization process. See Example 6-8.
Example 6-8 Externalizable example
public class User implements Externalizable implements Cloneable {
private static final long serialVersionUID = 1L;

Get WebSphere eXtreme Scale Best Practices for Operation and Management 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.