Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same native library loaded by different class loader

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.?

like image 573
Reji Avatar asked Sep 19 '25 18:09

Reji


1 Answers

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 an UnsatisfiedLinkError when used to load a native library into two class loaders.

like image 199
maba Avatar answered Sep 21 '25 07:09

maba