There are several ways.
The easiest way is to make the entire getInstance() method synchronized. A bit harder is
double-checked locking:
Then there is the holder class:
This nested class will only be initialized when needed; that is, when Singleton.getInstance() is called. Only then will it create the Singleton object. Since class loading is atomic, this approach is
thread safe as well.