Unsatisfiedlinkerror Native Library Dll Already Loaded In Another Classloader
I need to have a separate instance of the native library for each of mywebapps as each instance needs to contain data that is unique to thatparticular webapp. I have searched through the mail archives and reademails by Craig McLanahan explaining the classloader hierarchy. But Ihavenot been able to find anything specific to loading a unique instance of anative library for each webapp.
unsatisfiedlinkerror native library dll already loaded in another classloader
The problem is due to some configurations of your application server which cause to create more than one war or ear files and consequently it creates more than one deployed files. These deployed files attempt to have a concurrent access to your native library which loaded in a static block.
Usually a class that uses a native library will have a static initializer that loads the library. This way the class and the native library will always be loaded in the same class loader. With OpenCV the application code loads the native library.
Now there's the restriction that a native library can only be loaded in one class loader. Web applications use their own class loader so if one web application has loaded a native library, another web application cannot do the same. Therefore code loading native libraries cannot be put in a webapp directory but must be put in the container's (Tomcat) shared directory. When you have a class written with the usual pattern above (loadLibrary in static initializer of using class) it's enough to put the jar containing the class in the shared directory. With OpenCV and the loadLibrary call in the web application code however, the native library will still be loaded in the "wrong" class loader and you will get the UnsatisfiedLinkError.
When using the ArcSDE Java API in an environment with multiple classloaders; for example servlet container, the following error occurs:"java.lang.UnsatisfiedLinkError: Native Library jsg83.dll already loaded in another classloader"The error may be returned in a Web client or a log file associated with the container; for example, Tomcat or ServletExec.
The ArcSDE Java API uses Java classes in the jsde83_sdk.jar that call the native library, jsg83.dll or .so on Unix platforms, in the $SDEHOME/bin directory. Due to a limitation of the JVM classloader, these Java classes should only be loaded once per process. See the Related Information article below for additional information on this issue.
In some cases, the applications are hosted by some other classloaders (e.g. Mavin plug-in host, Osgi, etc.) that actively load and unload the applications on demand. That causes the Javet native library to be loaded repeatedly. However, JVM only allows one memory copy of a particular JNI library regardless of at which classloader it stays.
By default, Javet treats that as an error and prevent all API from working. But, applications may want to suppress this error because the Javet native library has already been loaded. Yes, Javet allows that. Here is a sample.
Exception: Exception in thread: java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'Native Library C:\WINDOWS\system32\sapjcorfc.dll already loaded in another classloaderat com.sap.mw.jco.JCO.(JCO.java:566)
Class Loader did not unload native library when applet closedError Message: Java Exception: java.lang.UnsatisfiedLinkError: Native Library C:\DRIVERS\CP8\akl5033\bin\Bug.dll already loaded in another classloaderNative Library Puiss loaded.java.lang.UnsatisfiedLinkError: Puiss
Evaluation: In the current VM implementation, a native library can only be associated with one classloader. Thus, when multiple applets attempt to use the same library, the VM tries to associate the library with more than one classloader, and that's why it fails. Thus, this is a limitation of the current VM implementation, and it is not a bug.
cannot load same DLL from more than one applet in browserError Message: unsatisfied link error", "dll already loaded by an xxxxx classloader". Evaluation: This is intentional. Each applet is loaded with its own classloader, and a native library cannot be loaded by more than one classloader.This is in part a security concern, as we don't want one classloader's app to muck up another classloader's app by tampering with native library state.
In SAP J2EE Engine as well as in INQMY AppServer each application is loaded in its own classloader. Reason: security, application isolation.That's why if two applicatinos use JCO.jar and each includes it into own EAR file then jco is loaded twice in different classloaders and these classloaders try to load the native library simultaneously, this fact explains the error message.The same may happen with any other stuff which uses native code.
java.lang.UnsatisfiedLinkError: Native Library ZebraNativeUsbAdapter_32.dll already loaded in another classloaderI should avoid the server reload because I have to stop all my applications instead of just the updated one. 350c69d7ab