deepak Wrote: carter below is small code for singleton pattern.
The constructor is private and if single object is created, this is fine. If you use multiple threads you need to protect the getInstance() through synchronization other wise it might return two different instances of Singleton object
Its not thread safe, multiple threads might compete for getInstance() and 2 threads might end up with totally different instances. One approach to solve this is by using double checked locking, but that has its own share of concerns like the Instance being available to a different thread even before the initialising thread has completed the initialisation i.e initializing the state.
In the book Effective Java this concept has been clearly explained.