Recently i saw and heard a new concept (atleast to me) with Serialization. What i saw is we have a DAO classes for Hibernate to talk to DB, that class and all implements Serialization. I have asked the developer saying that we need to do serialization when we transfer object. He told me in a multithreaded environment, either we need to implement interface or serialization. But i am not convinced with his statment.
We are backend application and we are providing webservices to the frontend. So we are having frontend faced classes, business classes and DAO classses. In what area this Serialization to be used.
Does the developer is correct on multihreaded and Serialization?
You have to Implement Serializable in order to convert your Object to bitStream no matter what you doing with that.
Only thing , you have to consider in multithread environment, ObjectStream is not locking while writing the object. So if your Object state going be modify by multiple threads at the same time. it is application responsibility to lock and write in safe.
This SO provides more info regarding this.
"He told me in a multithreaded environment, either we need to implement interface or serialization"
What you mean by implement interface ? any interface ? or proxies ?
For DAO layer. As per JPA spec
If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the
entity class must implement the Serializable interface
So JPA does not force you to do Serializable unless you want to serialize external ( like send object in remote / writing into file and so).But it is nothing harm to implement Serializable , since it is just marker Interface. IMHO It is always good practice to implement in entity class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With