tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Benzel <ben...@entelos.com>
Subject RE: Classloader, JNI and "already loaded in another classloader"
Date Sat, 02 Jun 2001 16:59:57 GMT
I may not be able to do what I need to do partly because of the limitations
of the C++/DLL.  As I mentioned in the original email, this is legacy 
code and it was never meant to be a "shared" library as it uses a 
number of static variables to hold data.  So I really do need separate
data segments for each running webapp.

When webapps/aaa starts up, it reads from disk the data that is specific
to that webapp instance into the (often static) variables and data
structures within the instance of C++/DLL.  If webapps/aaa and webapps/bbb 
were running in different processes, then I would agree with your first 
paragraph.  There would be a single instance of the code segment and 
2 instances of the data segments.  I believe that the separation of the 
data segments is managed by the operating system (not sure about this).
Thus if webapps/aaa and webapps/bbb were running in separate instances
of Tomcat under separate JVM's, then there would be no problem.

However, when running under a single Tomcat instance, I think
that there is only 1 process (only one JVM in use).  There may be several 
threads, but only one process is in use.  Therefore, there is only 1 data 
segment that can be used.

Or am I completely off base?  If so, could you please help me to understand
how the Java Bean you describe can be used to create 2 data segments running
in the same process?  I have tried the following suggestion from Bo Xu:

- don't put "System.loadLibrary("JCoreImpl")" in Servlet class,
   but put it in a utility class which is loaded by a classloader who is
   "upper" than the classloader of "aaa" or "bbb".  for example, put this
    utility class and the native code Both in TOMCAT_HOME/lib

- then in the "init" method of those Servlet classes in webapp "aaa"
   or "bbb", first load that utility class, then/so load the native code.

The DLL is loaded once (the classloader doesn't load the DLL a second time
if it is already loaded) and one data segment is used as can be seen by
printing out the values of some of the static variables within the DLL.
JNI native libraries also cannot be loaded into more than one classloader.

Sorry if I'm being dense about this.  I really appreciate you taking the
time
to respond.

-----Original Message-----
From: Pae Choi [mailto:paechoi@earthlink.net]
Sent: Friday, June 01, 2001 11:33 AM
To: tomcat-user@jakarta.apache.org
Subject: Re: Classloader, JNI and "already loaded in another
classloader"


I may be completely misunderstanding your case. However, the DLL itself
is runnging as a single instance but has separate data segments for its
each reference. Fro example, 2 users and 1 DLL will result a single instance
of code segment and 2 different data segments for each user respectively.
Agreeable?

If so, isn't java bean as a user calling the DLL twice create the same
scenario?
So two different accesses from the jb's user can get the separate data
returned
by the DLL.


Pae



-----Original Message-----
From: Mark Benzel <benzel@entelos.com>
To: 'tomcat-user@jakarta.apache.org' <tomcat-user@jakarta.apache.org>
Date: Friday, June 01, 2001 11:18 AM
Subject: RE: Classloader, JNI and "already loaded in another classloader"


>Yes, it makes sense.  However, I'm not sure if it solves my problem.  In
>the scenario you describe, I would want to have 2 Java Beans, each
accessing
>a separate instance of the C++/DLL.  That's because the data contained in
>the
>C++/DLL used by webapps/aaa is different than the data contained in the
>C++/DLL
>used by webapps/bbb.  An equivalent case would be running the same
>standalone
>Java application twice with each instance of the Java application accessing
>a
>different set of data.
>
>Thanks,
>
>Mark
>
>-----Original Message-----
>From: Pae Choi [mailto:paechoi@earthlink.net]
>Sent: Friday, June 01, 2001 10:30 AM
>To: tomcat-user@jakarta.apache.org
>Subject: Re: Classloader, JNI and "already loaded in another classloader"
>
>
>Just to give a thought for your situation, how would you think if we
>place a plain java bean(i.e., common wrapper class) that interact with the
>c++/dll module and provide the access from the Web components, i.e.,
>servlet/jsp --- the jb's user --- to the java bean(jb). In that case,
>multiple jb's users are accessing a single dll through the jb.
>
>Does it make sense to you?
>
>
>Pae
>
>
>
>>I have a webapp running under Tomcat 3.2.1 that needs to make JNI calls in
>>order to access data and methods in legacy C++ code.  A servlet is loaded
>on
>>startup of the webapp that, as part if its init method, causes a data set
>>specific to that webapp instance to be loaded into the C++ data
structures.
>>This Java code for this servlet contains the following:
>>
>>    static
>>    {
>>        try {
>>            System.loadLibrary("JCoreImpl");
>>            System.out.println("JCoreImpl loaded");
>>            m_bLibraryLoaded = true;
>>        } catch (UnsatisfiedLinkError e) {
>>            m_bLibraryLoaded = false;
>>            System.out.println("JCoreImpl NOT loaded " + e);
>>        }
>>    }
>>
>>Things work fine if there is only one webapp (let's call it
"webapps/aaa").
>>If I have a second webapp ("webapps/bbb") that is identical to webapps/aaa
>>except for the data set used in the C++ data structures, then webapps/aaa
>>starts up just fine, but when webapps/bbb is started I get an error
stating
>>that:
>>
>>JCoreImpl NOT loaded java.lang.UnsatisfiedLinkError: Native Library
>>E:\WebStation\binDebug\JCoreImpl.dll already loaded in another classloader
>>
>>I need to have a separate instance of the native library for each of my
>>webapps as each instance needs to contain data that is unique to that
>>particular webapp.  I have searched through the mail archives and read
>>emails by Craig McLanahan explaining the classloader hierarchy.  But I
have
>>not been able to find anything specific to loading a unique instance of a
>>native library for each webapp.
>>
>>Any ideas?  Thanks,
>>
>>Mark

Mime
View raw message