java - Avoid multiple instances of Singleton? -



java - Avoid multiple instances of Singleton? -

this question has reply here:

what efficient way implement singleton pattern in java? 25 answers

i believe when singleton object gets serialized , deserialized upon plethora of times in series, there multiple instances of singletons created.

how can avoid such situation?

normally, when creating singleton, create sure there 1 instance of it. way:

public static class singleton{ private final static singleton instance; private singleton(){} public static singleton getinstance(){ if(instance == null) instance = new singleton(); homecoming instance; } }

putting constructor private makes sure no 1 except class can create instance of singleton.

you need phone call singleton getinstance , singleton work on side.

java scala design-patterns singleton

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -