我有一个插件,其中包含工作区中所有项目都可以访问的自定义 Xpath 函数。在创建插件时,它将其创建为单例,因为它需要扩展和扩展点。这样做是为了让自定义功能只注册一次吗?
[ ] 这个插件是单例的
同样在运行时,这是否意味着所有利用自定义函数的应用程序都需要等待另一个应用程序才能调用自定义函数?如果是这样,这不会减慢一切吗?或者它们可以并发调用函数并且彼此之间对插件没有等待依赖性?
最佳答案
此标志的作用是确保仅加载插件的一个版本。因此,如果 RCP 中同时存在插件的 1.0.0 版和 2.0.0 版,则只会使用其中一个(通常是最高版本)。
它不会以任何方式影响插件的执行方式。
来自“Bundle-SymbolicName”的 OSGi 规范:
singleton - Indicates that the bundle can only have a single version resolved in an environment. A value of true indicates that the bundle is a singleton bundle. The default value is false. The Framework must resolve at most one bundle when multiple versions of a singleton bundle with the same symbolic name are installed.
关于java - Eclipse 插件单例设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37028857/