Friday, September 2, 2016

Serialization

used for File Storage, NWK communication, Database, Web usage
  • Translating Data structure/Object state into a format that can be stored (in File, Memory buffer, transmitted across a nwk connection) and recreate later in the same or another computer environment.
  • a method of persisting objects, for example writing their properties to a file on disk, or saving them to a database.
  • Transfer data over network between cluster Nodes or between servers and clients

-- Serialization is a key Technology behind any RPC/RMI

 Each time a serialized instance is deserialized, a new instance gets created.
To avoid this, use readResolve(): 
private Object readResolve() {
        return SESSION_FACTORY;
    }
Each time a serialized instance is deserialized, a new instance gets created.
To avoid this, use readResolve(): 
private Object readResolve() {
        return SESSION_FACTORY;
    }

Serialization vs Externalization
The results show that Java serialization is slow for a small number of objects, but good for a large number of objects. Conversely, XML and JSON can outperform Java serialization for a small number of objects, but Java serialization is faster for a large number of objects. Kryo and other optimized binary serializers outperform Java serialization with both types of data.
Java serialization writes out not only the full class name of the object being serialized, but also the entire class definition of the class being serialized, and all of the referenced classes. The class definition can be quite large, and seems to be the main performance and efficiency issue, especially when writing out a single object.
Externalizable
It is possible to optimize Java serialization through implementing the Externalizable interface. Implementing this interface avoids writing out the entire class definition, just the class name is written. It requires that you implement the readExternal andwriteExternal methods, so requires some work and maintenance on your part, but is faster and more efficient than just implementing Serializable






No comments:

Post a Comment