Fair Issac Interview Question
Financial Software DevelopersHey Shunya,
Can you explain a bit more on how you go about having many instances of Singleton using Reflection? and How exactly you can achieve the fail condition?
However, i totally agree that Singleton won't actually behave the way it is intended, in a clustered environment...
Even if you use Reflection you can actually control the no of instances created. Think about this. Hint: Count
1) Reflection
2) If Singleton class implements either Serialization or Cloneable interface and provide the support to both.
3) In multi-threaded environment if synchronization of createInstance() is not taken care.
4) If Singleton class is loaded in Multiple JVM. In case of distributed env.
5) Multiple java class loaders loads the class.
6) Multiple factory taking care of creating the instance is not implemented properly.
7) Subclassing the singleton class.
8) Double checked locking.
9) If class Garbage collected and it again reloaded.
10) Programmatic reloading the class mainly in case of Servlet engine.
1. If the class can be serialized then we need to have the readResolve method for our help.
- helper May 09, 20082. If the same class is loaded by two different class loaders then we just cant stop this.