Re: Thanks for the note on JNI and class loading in the release notes

2001-09-17 Thread Jochen Schneider

Hi Jonathan,

we had the same problem and fixed it in the way described now in the Tomcat
documentation.

Probably one additional remark should be added to the documentation :

If you place the Java code loading the native library outside of the web
application (for example in $CATALINA_HOME/common/lib) it is loaded only
once and the problem is solved.

This sollution has some implication : The classes containing the native code
are loaded by a classloader which has no knowledge about any class which
resides in \Web-inf\lib. You will get an exception if you try to instanciate
a class which resides in the \Web-inf\lib directory from your native code!
You will also get an exception if you try to import a class which resides in
the \Web-inf\lib\ directory from your java code in $CATALINA_HOME/common/lib
since the two classes are loaded by different classloaders.

This will not work (ClassA in $CATALINA_HOME/common/lib ansd ClassB in
\Web-inf\lib\ ) :

ClassA :

  import ClassB;
  public native static void doSomething(ClassB obj);


ClassB :

  import ClassA
  public static void main(String[] args) {
  ClassA.doSomething(this);
  }


Now it works again :

ClassA :


  public native static void doSomething(Object obj);


ClassB :

  import ClassA
  public static void main(String[] args) {
  ClassA.doSomething((Object)this);
  }


Is this description correct? How do you handle this problem? Is there a more
elegant sollution ?

Regards,
Jochen


P.S: Sorry for posting this message to tomcat-user. Mea culpa.


-
Tomcat 4.0 and JNI Based Applications:
-

Applications that require native libraries must ensure that the libraries
have
been loaded prior to use.  Typically, this is done with a call like:

  static {
System.loadLibrary(path-to-library-file);
  }

in some class.  However, the application must also ensure that the library
is
not loaded more than once.  If the above code were placed in a class inside
the web application (i.e. under /WEB-INF/classes or /WEB-INF/lib), and the
application were reloaded, the loadLibrary() call would be attempted a
second
time.

To avoid this problem, place classes that load native libraries outside of
the
web application, and ensure that the loadLibrary() call is executed only
once
during the lifetime of a particular JVM.



- Original Message -
From: Jonathan Eric Miller [EMAIL PROTECTED]
To: Tomcat Developer List [EMAIL PROTECTED]
Sent: Saturday, September 15, 2001 5:59 AM
Subject: Thanks for the note on JNI and class loading in the release notes


 I'm guessing that Craig is the one that added the section about JNI and
 class loading in the RC1 release notes. I just wanted to say that I
 appreciate that you documented this.

 I also noticed that you fixed a problem that I noticed with the Base64
 encoder where it had trailing zeroes.

 Thanks, Jon







Thanks for the note on JNI and class loading in the release notes

2001-09-14 Thread Jonathan Eric Miller

I'm guessing that Craig is the one that added the section about JNI and
class loading in the RC1 release notes. I just wanted to say that I
appreciate that you documented this.

I also noticed that you fixed a problem that I noticed with the Base64
encoder where it had trailing zeroes.

Thanks, Jon