With 2 web servers, will a singleton class have 2 instances?
In software engineering, the multiton pattern is a design pattern which generalizes the singleton pattern. Whereas the singleton allows only one instance of a class to be created, the multiton pattern allows for the controlled creation of multiple instances, which it manages through the use of a map.
In object-oriented programming, a singleton class is a class that can have only one object (an instance of the class) at a time.
Cloning: Cloning is a concept to create duplicate objects. Using clone we can create copy of object. Suppose, we create clone of a singleton object, then it will create a copy that is there are two instances of a singleton class, hence the class is no more singleton.
It falls under the category of the creational design pattern in Java. A Singleton class in Java allows only one instance to be created and provides global access to all other classes through this single object or instance.
Both the web-servers will have separate instances of their application processes be it .net or java. So Yes, both the servers will have their individual instances of your singleton class.
Regardless of the fact that these two web servers are two different physical machines, even if they are on the same server, they will definitely run entirely on different processes. Each process will load its objects in memory separately from any other process.
specifically in case of asp.net
-
Even in the single web server, each site will cause separate instance of the Singleton class. Because each site in asp.net worker process is loaded in separate application domain, no two domains can interfere between each others' objects. So in case of asp.net even the single web server having single asp.net worker process can/will have multiple instances of the singleton class each separate from another.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With