此内容没有您所选择的语言版本。

1.3. Class Loading Algorithm


Overview

The OSGi bundle class loading algorithm plays a key role in the OSGi framework. Ultimately, it is this algorithm that defines the relationship between a bundle and its dependencies.

Requirements on a bundle class loader

Here are some of the requirements that a bundle class loader must satisfy in order to support a flexible and consistent class loading architecture:
  • In order to avoid loading multiple copies of a class, the bundle class loader must first of all try to find the class in one of its dependent bundles.
  • The bundle class loader must never load a duplicate copy of a class into its class space.

Bundle class loading algorithm

The following is a simplified description of the bundle class loading algorithm (for example, it does not enumerate all of the ways in which class loading can fail). For a full description of the algorithm, see the Runtime Class Loading section of the OSGi Core Specification.
  1. If the class belongs to one of the java.* packages or any packages listed in the org.osgi.framework.bootdelegation property, the bundle class loader delegates to the parent class loader.
  2. If the class belongs to one of the packages listed in Import-Package, the bundle class loader delegates loading to the corresponding exporter bundle.
  3. If the class belongs to one of the packages imported by Require-Bundle, the bundle class loader delegates loading to the corresponding exporter bundle.
    Note
    It is strongly recommended that you avoid using the Require-Bundle header. OSGi dependencies are meant to be defined at package granularity, not bundle granularity.
  4. Next, the bundle class loader looks for the class amongst its internal classes (inside its own JAR file).
  5. Next, the bundle class loader searches the internal classes of any fragments attached to the bundle.
  6. Finally, if the class belongs to one of the packages imported using DynamicImport-Package, the bundle class loader delegates loading to the corresponding exporter bundle (if there is one).
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.