I have some objects which are accessed concurrently by RMI serialization. Recently I had written custom serialization methods:
/** This method is made to omit serialization of this.order */
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException
{
Order tmpOrder = this.order;
this.order = null;
out.defaultWriteObject();
this.order = tmpOrder;
}
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, ClassNotFoundException
{
in.defaultReadObject();
}
I don’t want to permit to spoil this.order by concurrent RMI thread.
- Do I need to make writeObject synchronized ? or
- Does the RMI framework do all the best to synchronize the access to the object ?
In second case my synchronization could even cause deadlocks in RMI. The general contract of JAVA API is that a method is called by one thread except noted specifically. So if I should follow the rule I should leave the writeObject w/o any synchronization. Is this correct ?
Another solution to my problem without answering the question is certainly declaring private static final ObjectStreamField[] serialPersistentFields. (I cannot make a field transient because the object is not only a DTO but an JPA Entity also)
No you don’t. You have some objects that are accessed concurrently by Object Serialization.
No. The Object Serialization framework might, but it isn’t specified.