Jay Roy
asked on
Singleton in a cluster environment
hi guys
If there are two cache servers connected with a cluster and if i am using a singleton design pattern to create a singleton object, is it possible
that instance 1 is created in one server and instance 2 is created in another server ?
thanks.
If there are two cache servers connected with a cluster and if i am using a singleton design pattern to create a singleton object, is it possible
that instance 1 is created in one server and instance 2 is created in another server ?
thanks.
ASKER
thanks
One the contrary if i have one weblogic applicaiton server and i have 2 WAR projects deployed in it. Both the WAR projects have the same singleton java class. Will the singleton instance be in each of the WAR project or just one instance be used across both the WARS?
thanks
One the contrary if i have one weblogic applicaiton server and i have 2 WAR projects deployed in it. Both the WAR projects have the same singleton java class. Will the singleton instance be in each of the WAR project or just one instance be used across both the WARS?
thanks
I think if you have 2 WAR files you will end up with 2 instances of the singleton. That's because the goal is for each WAR to be completely isolated from the other - they shouldn't be able to communicate or affect each other. If they shared the same singletons that wouldn't be the case.
Doug
Doug
ASKER
Alright, but don't the two WARs share the same jvm if they are both deployed in the same application server?
Thx
Thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Aahh, its clear now. So there are two aspects to it,
Class loaders and
The JVM itself
thanks.
Class loaders and
The JVM itself
thanks.
ASKER
So I guess each (WAR)web-project will have its own class loader which will
Load the classes of that web-project when application server starts?
Load the classes of that web-project when application server starts?
Yes that's right. It allows the container to keep each project separate - which is usually the correct behavior.
Doug
Doug
ASKER
thanks
can you please help me with this question
https://www.experts-exchange.com/questions/27734431/threadsafety-in-jsp-servlet.html
can you please help me with this question
https://www.experts-exchange.com/questions/27734431/threadsafety-in-jsp-servlet.html
So on two different servers (which implies 2 different JVMs) you will get two different instances.
If you're saying these instances are being stored in a replicating cache then it would depend on the design of the caching software as to how it would handle this.
Doug