OSGi: What happens if not to unget service

时光怂恿深爱的人放手 提交于 2019-12-23 16:28:09

问题


This is the way how I get OSGi service:

ServiceReference reference = bundleContext.getServiceReference(Foo.class.getName());
 Foo foo=(Foo) bundleContext.getService(reference);

What happens if I don't do bunldeContext.ungetSerivice(reference) when I finished with service:

  1. If I registered service manually, for example in activator
  2. If I use declarative service and it is Singleton

回答1:


The OSGi framework maintains a use count of each service for your bundle. If your bundle does not unget the service, it will be released automatically by the framework when either your bundle stops or the service is unregistered.

It you are using Declarative Services, SCR will handle calling unget at the appropriate time in the life cycle of the component referencing the service.



来源:https://stackoverflow.com/questions/43154532/osgi-what-happens-if-not-to-unget-service

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