Pasupathi Rajamanickam
Pasupathi Rajamanickam

Reputation: 2052

Partially Deserializing a complex java object

I have a java class hierarchy as follows.

public class Results{
    private String _query;
    private CachedRowSetImpl _resultSet;
    //... getter setters
}

I've serialized List<Results> resultList, consider this List contains 100 items and each _resultSet having more than 1000 records. I have 2 questions,

  1. When we deserialize this object, my application memory will hold the entire object and will it create heap size problem?
  2. If it will create resource problem, when I deserialize, can I ignore _resultSet being deserialized meaning just query is enough?

Correct me, if my understanding is wrong.

Upvotes: 3

Views: 239

Answers (2)

Sashi Kant
Sashi Kant

Reputation: 13455

If you implement Externalizable,your readExternal will look somewhat like :

     public void readExternal(ObjectInput in) throws IOException,  
         ClassNotFoundException {  
             _query=(String) in.readObject();  
            if(//yourCondition){
             _resultSet=(CachedRowSetImpl) in.readObject();  
            }
         }

Upvotes: 1

Laszlo Hirdi
Laszlo Hirdi

Reputation: 1150

You should implement Serializable. The modifier "transient" can be used to ignore fields during serialization. I do not know what contained in CachedRowSetImpl but when you ignore that then only 100 String objects will not likely cause heap problem.

public class Results implements Serializable{
    private String _query;
    private transient CachedRowSetImpl _resultSet;
    //... getter setters
}

Upvotes: 0

Related Questions