-
1. Re: JNI Libraries, Classloaders and redeployment
adrian.brock Apr 5, 2002 12:33 PM (in response to redsolo)Tomcat doesn't support this.
In the other thread, I suggested writing an MBean to
load/unload the library.
Regards,
Adrian -
2. Re: JNI Libraries, Classloaders and redeployment
redsolo Apr 6, 2002 7:52 AM (in response to redsolo)Ok. I will try to find that thread here in the forums.
If I load the library in the MBean, can all my servlets access it then ?? Or do they have to go through the Bean ?
BTW what is a MBean ? Where can i find more info about how to write a mbean ?? -
3. Re: JNI Libraries, Classloaders and redeployment
adrian.brock Apr 6, 2002 12:50 PM (in response to redsolo)An MBean is a managed bean. They are used in the
core JBoss architecure.
If you look at jboss.jcml, these are all mbeans.
You can use the mbean to load a class that wraps the
native implementation. The mbean is loaded at server
start, i.e. the code only happens once.
The servlets can then reference that class, probably
through some sort of static factory method?
The trouble with Tomcat is that when you redeploy,
you get a new classloader, so the class is reloaded.
But the old class is probably still on the heap waiting
to be garbage collected.
Regards,
Adrian -
4. Re: JNI Libraries, Classloaders and redeployment
davidjencks Apr 6, 2002 1:11 PM (in response to redsolo)I am not an expert on JNI, however when I investigated I got the strong impression that java goes to great lengths to prevent you from loading a native library twice in the same vm under any circumstances. I would certainly like to know if I am wrong, preferably by means of an example;-)
-
5. Re: JNI Libraries, Classloaders and redeployment
jules_gosnell Apr 7, 2002 4:26 AM (in response to redsolo)
I had a similar problem with a servlet that I was developing.
I split the JNI stuff off into another servlet, which needed no further development. The servlet which was being actively developed then consumed the jni based one.
The second servlet could then be bounced independently of the JNI code.
I did look around for a way to unload native libs so I could load in init() and unload in destroy() - but could not find one....
Perhaps I missed something ?
Jules -
6. Re: JNI Libraries, Classloaders and redeployment
user57 Apr 7, 2002 5:14 AM (in response to redsolo)Try putting your classes that use JNI into lib/ext (2.x) or lib/ (3.x). This will allow your servlets & other components to see the classes, but not have problems realoading.
If you want to reload the classes which load JNI libraries then you are hosed. If this is the case consider rearchitecting to put JNI into seperate class library which can be detached from the app, thus allowing it to live in lib/ext or lib/.
--jason -
7. Re: JNI Libraries, Classloaders and redeployment
redsolo Apr 8, 2002 2:42 AM (in response to redsolo)Another question about MBeans. Can all users add MBeans to the JBoss ? Since we're only a user among several other user at our web host, the host admins wont let any user do any special things that isnt allowed outside autoconfiguring.
Im new to MBeans and Beans (as well), is there any good tutorial on how to write a small bean that wraps the JNI code, and also how to call it ??
Does the MBean have to exist when the server is started, or can it be added later (only once) ?
THanks -
8. Re: JNI Libraries, Classloaders and redeployment
user57 Apr 8, 2002 3:10 AM (in response to redsolo)Try the JMX Book that Juha wrote, it is very informative & helpful.
--jason