How many number of Instance can be there when same singleton class is packaged in two war file(and both war files are packaged in one ear file)
Cas1
MyUnderstanding As per my understanding for singleton class there will be a single instance per JVM. So as per this answer for above should be one instance as there will be one instance of jvm for the ear file.
Case2
But on differnt sites(one at http://www.code开发者_如何学Pythonranch.com/t/520891/java/java/Singleton-Diff-WAR-files-same) , folks have also mentioned singleton produces the single instance for a class loader. they said for two war files there will be two class loader . So ther will be two instance of singleton.
What is the right answer?
If second case is right can we say below statements
1)For singleton class there will be a single instance per classloader(here i mean classloader hirerchy in a jvm instance that includes bootstrap loader, application class loader) not for jvm.
2)For two war files packaged in same ear file there will be two classloader hirerchies under same jvm instance
posted at http://forums.oracle.com/forums/thread.jspa?threadID=2253940&tstart=0 but not concrete answer
1) If your class is in each WAR, then there will be an instance per webapp (classloader herarchy).
2) Yes.
精彩评论