Question

While I was going through the explanation of readResolve method , lot of references explain that this method will be useful to gurantee the singleton property when singleton class is deserialzied while object of that class is serialized and transferred over RMI .

Now my question is when RMI call takes place , Singleton class Object will be transported over different JVM (having different classloader) , so after deserialization we will have another instance of singleton class (in different JVM) . Am I right ?

So in the context of RMI calls , what is use of implementing readResolve method ?

Was it helpful?

Solution

So that if you send it again, it resolves to the one that is already there. Which would probably be contrary to your intention. Don't confuse yourself by using singletons in RMI.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top