Please consider the following scenario:
I have two java classes, loaded using different system class loaders. I have a native library that has a queue implemented. Both the classes will load the same library, and add elements to the queue. Is it possible? If so, will the native library implementation be shared across the two classes.?
According to the JNI Specification it is not possible.
In the JDK, each class loader manages its own set of native libraries. The same JNI native library cannot be loaded into more than one class loader. Doing so causes
UnsatisfiedLinkError
to be thrown. For example,System.loadLibrary
throws anUnsatisfiedLinkError
when used to load a native library into two class loaders.