Hi,
Java has a known limitation whereby native libraries can only be loaded once per
JVM. That means that if two separate classloaders try to System.loadLibrary() on the
same library, the second one will fail and subsequently all function calls requiring
access to the library will fail.
Sun has posted a workaround. To guarantee the library is only loaded once, all
classes having a dependency on the native library should be instantiated in the child
classloader. For for example if classes A and B make use of class C, where class C
actually calls:
static
{
System.loadLibrary("mylib");
}
Then class C should be instanciated in a some classloader whereby classes A and B
should be loaded in one of the children of that classloader. This guarantees for that
any numbers of instances of classes A and B there will only be one instance of C,
always.
The problem is that there doesn't seem to be a way to do this under Tomcat and as
a result, it is impossible to safely use JNI under Tomcat. For example, I found that
upon modifying and recompiling classes A or B, hitting some JSP file which referred to
them caused them to load in a new classloader which caused C to be loaded a second
time (since I could only get class C to load in the same classloader as A and B).
I await your feedback.
Thanks,
Gili
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>