OSGi:如果不取消服务会怎样? [英] OSGi: What happens if not to unget service

查看:97
本文介绍了OSGi:如果不取消服务会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我获得OSGi服务的方式:

This is the way how I get OSGi service:

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

完成服务后,如果不执行bunldeContext.ungetSerivice(reference)会发生什么情况:

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

  1. 如果我手动注册了服务,例如在激活器中注册了
  2. 如果我使用声明式服务,并且它是Singleton

推荐答案

OSGi框架维护捆绑软件中每个服务的使用计数.如果您的捆绑软件没有取消服务,则当捆绑软件停止或未注册服务时,框架会自动释放它.

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.

如果您使用的是声明式服务,SCR将在引用该服务的组件的生命周期中的适当时间处理unget调用.

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.

这篇关于OSGi:如果不取消服务会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆