Anil kumar Sakala wrote:
Each time we deserilize read resolve returns public static final variable value which is getting populated with new instance() , for every deserialization.
Seetharaman Venkatasamy wrote:readResolve wont create new Instance it return existing Instance . if you are not implement readResolve then deserialize create new Instance that is why readResolve needed
Vineet Yekurde wrote:As per above , what i serialized is i=5,d=5.5. Buf after deserialization what i get is : i=1,d=1.1
is this fine ? No ....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Vineet Yekurde wrote:As per above , what i serialized is i=5,d=5.5. Buf after deserialization what i get is : i=1,d=1.1
is this fine ? No ....
Actually: Yes.
First off, the idea of a mutable Singleton seems bizarre; but even given that, presumably the whole point of having a singleton is that there's only one of them, and it should always reflect the latest state. You appear to want your de-serializer to act as a "resetter", which strikes me as:
(a) Dangerous.
(b) If you absolutely must have it work that way, you've written your readResolve() method wrong: What it needs to do is get the instance and update it before returning it.
Winston
Vishwakarma, Shiv
SCJP 1.4, SCWCD 5
Shiv Vishwakarma wrote:I read at many places that overriding the readResolve() we can handle this problem. but I am still have this one doubt, where exactly this readResolve method is present that we should override.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Vishwakarma, Shiv
SCJP 1.4, SCWCD 5
Shiv Vishwakarma wrote:But today actually when I am trying it, I am not able to do it. And if we are not overriding this method then are we providing this method from our side, and how the JVM knows whether the readResolve method is present and it has to return the already created instance of singleton class.
Please provide any working example of the same, as I tried and it didn't work
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here