When a native library is loaded into the JVM, it can only be loaded from a single bundle at a time. If the bundle is restarted or updated, the existing native library is reused for the new version of the bundle. The reason for this is that the JVM ensures that the fully qualified path of the native library is associated with a single ClassLoader
instance. Subsequent loads of the native library will fail.
If the bundle is uninstalled completely, the native library may be subject to unloading. Note that this only occurs when the ClassLoader
instance associated with the bundle is garbage collected, which may be some time after the bundle has been stopped.
Note that as discussed earlier in this chapter, the OSGi specification only supports native libraries that have no transitive native dependencies. This restriction is primarily limited to the support in Java for loading such transitive dependencies.