I have several classes that use the same JNI library, called “jni”. In each of those classes, I have a System.loadLibrary() call in the class’s static initializer:
Class class1 {
static{
System.loadLibrary("jni");
}
...
}
Class class2 {
static{
System.loadLibrary("jni");
}
...
}
The only problem is, I only want System.loadLibrary() to be called once, since it can take a while. Is there an easy and clean way to prevent multiple loadings of the same library?
If the library has already be loaded any subsequent calls to load the same library will be ignored.
System.loadLibrary:Runtime.loadLibrary: