3 ms·
10 Interview questions on Singleton Pattern in Java
- personalcompute 16y agoMost of these are trivial or just generic threadsaftey questions. You probably should not be using the singleton pattern in the first place though, global state is not an elegant solution.
- prodigal_erik 16y agoIf you really need a lazy Java singleton for some reason, letting the classloader construct it (guaranteed to happen at most once, and as late as possible) is effortless and more robust than screwing around with the synchronization yourself. On the other hand, interviewing candidates has so shaken my faith that I'd be very impressed to meet anyone who knew this. http://en.wikipedia.org/wiki/Singleton_pattern#The_solution_of_Bill_Pugh http://en.wikipedia.org/wiki/Singleton_pattern#The_solution_...
- javabuddy 16y agoAgree, Singleton loaded by Classloader is most robust way of doing it but they I just think why people discovered double check locking pattern for creating singleton instance ?