أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Singleton design pattern is not to be confused with multi threading in a single instance. In singleton pattern only one instance for the class will be created at all times. This is useful in case of using logger objects which are used across multiple classes and so a single instance is preferred to avoid resource overhead.
In case of multi-threading multiple objects of the class can be created. However, threads are created on a single instance of each class and access the key resources using synchronised keyword.
A singleton class had to be protected in a multi-threaded environment by using synchronised keyword on its instance creation code. Else there is a possibility of multiple threads creating multiple objects.