Singleton across JVM or Application instance or Tomcat instance

前端 未结 5 1193
星月不相逢
星月不相逢 2020-11-30 04:17

If I deploy and run 2 instances of same application on a single instance of Tomcat(Or any other server). Then a single object(of a Singleton class) would be created:

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 04:45

    As far as I know, a singleton is unique per classloader. So I think the answer to your question depends on the way the container loads the web application.

    If it allocates one classloader per web app, then it seems like you would get two, completely independent, singleton objects. If it allocates one classloader and all web apps use it, then they share the same singlet one instance.

提交回复
热议问题