Java

Topic: Serialization

What are the ways to speed up Object Serialization? How to improve Serialization performance?

The default Java Serialization mechanism is really useful, however it can have a really bad performance based on your application and business requirements. The serialization process performance heavily depends on the number and size of attributes you are going to serialize for an object. Below are some tips you can use for speeding up the marshaling and un-marshaling of objects during Java serialization process.    Mark the unwanted or non Serializable attributes as transient. This is a straight forward benefit since your attributes for serialization are clearly marked and can be easily achieved using Serialzable interface itself.    Save only the state of the object, not the derived attributes. Some times we keep the derived attributes as part of the object however serializing them can be costly. Therefore consider calcualting them during de-serialization process.    Serialize attributes only with NON-default values. For examples, serializing a int variable with value zero is just going to take extra space however, choosing not to serialize it would save you a lot of performance. This approach can avoid some types of attributes taking unwanted space. This will require use of Externalizable interface since attribute serialization is determined at runtime based on the value of each attribute.    Use Externalizable interface and implement the readObject and writeObject methods to dynamically identify the attributes to be serialized. Some times there can be a custom logic used for serialization of various attributes.

Browse random answers:

Define Serialization? What do you mean by Serialization in Java?
Why is Serialization required? What is the need to Serialize?
What is the Difference between Externalizable and Serializable Interfaces?
When will you use Serializable or Externalizable interface? and why?
What are the ways to speed up Object Serialization? How to improve Serialization performance?
What is a Serial Version UID (serialVersionUID) and why should I use it? How to generate one?
What would happen if the SerialVersionUID of an object is not defined?
Does setting the serialVersionUID class field improve Java serialization performance?
What are the alternatives to Serialization? If Serialization is not used, is it possible to persist or transfer an object using any other approach?
What are transient variables? What role do they play in Serialization process?
Why does serialization NOT save the value of static class attributes? Why static variables are not serialized?
How to Serialize a collection in java? How to serialize a ArrayList, Hashmap or Hashset object in Java?
Is it possible to customize the serialization process? How can we customize the Serialization process?
How can a sub-class of Serializable super class avoid serialization? If serializable interface is implemented by the super class of a class, how can the serialization of the class be avoided?
What changes are compatible and incompatible to the mechanism of java Serialization?
How to make a Java class Serializable?
How many methods Serializable has? If no method then what is the purpose of Serializable interface?
What is serialVersionUID? What would happen if you don't define this?
While serializing you want some of the members not to serialize? How do you achieve it?
 What will happen if one of the members in the class doesn't implement Serializable interface?
 If a class is Serializable but its super class in not, what will be the state of the instance variables inherited from super class after deserialization?
 Can you Customize Serialization process or can you override default Serialization process in Java?
 Suppose super class of a new class implement Serializable interface, how can you avoid new class to being serialized?
Which methods are used during Serialization and DeSerialization process in java?
Suppose you have a class which you serialized it and stored in persistence and later modified that class to add a new field. What will happen if you deserialize the object already serialized?
What are the compatible changes and incompatible changes in Java Serialization Mechanism?
Can we transfer a Serialized object vie network?
Which kind of variables is not serialized during Java Serialization?