Can singleton be implemented in OSGi environment

邮差的信 提交于 2019-12-11 05:54:22

问题


As far as I understand every bundle in osgi has its own classloader. Let's suppose we have three bundles:1,2,3. There is singleton class in bundle 1. Bundle 2 loads singleton and makes some changes in it. And as far as I understand, if bundle 3 loads singleton too its version of singleton is different. So Singleton in bundle 2 != singleton in bundle 3.

Are my statements right? If they are right, so it is not singleton, is it?


回答1:


It is true that each bundle has its own classloader, but the classloaders are "shared", depending on the Manifest import-package declaration. Each bundle classloader maintain a private mapping table that tells it which classloader is responsible for providing classes from a particular package. In your case, when bundle 2 loads the singleton, it does not load the Singleton by itself, it asks the bundle 1 classloader for the class.



来源:https://stackoverflow.com/questions/37321168/can-singleton-be-implemented-in-osgi-environment

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