what's the scope of a static field?

荒凉一梦 提交于 2019-12-05 13:20:22
ianpojman

The scope of a static is global - within its owning classloader. A JVM can create multiple classloaders and load separate instances of your class in each of new classloaders.

Statics are not global per JVM, they are global per classloader. If the class with the static field is loaded in a different classloader, its static members won't be visible within a different classloader.

How are project A and project B deployed? Are they in the same classloader?

I'm not familiar with servicemix, but I imagine it deploys separate apps in separate classloaders, just like a Java EE app will deploy different versions of the same app in different classloaders, so you can run app 1.0 and app 1.1 side-by-side, and they won't affect each other.

This is by design.

If this is the case, you need something independent to maintain shared state. (e.g. a database)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!