As we all know that Singleton
Pattern is a design pattern used to restrict the instantiation of a class to a single object i.e. we can create only one object for a class.
My doubt is that... Does this applies for a JVM. i.e. In a JVM instance will there be only one instance of a singleton class.
To make it more clear I will take the example of a
Tomcat application. Suppose I have a
java web project called singledemo with a Singleton class in it.
I deploy the same project in a tomcat as two different applications - singledemo and singledemo-test.
I run both the applications and execute the code to access the singleton class in both applications.
How many objects of the singleton class will be created? I believe that the entire tomcat server runs on a single JVM instance, with all the web applications running on it.