[Q] unLoadLibrary ?

O

obladi

Hi. I'm using DLL through JNI. However, when I got an Exception before
calling the DLL library, there is a "java.lang.UnsatisfiedLinkError: xxx.dll
already loaded in another classloader". Of course, it wokrs perfectly when
there is no Exception. How can I get this stuff work fine? Is there any
method something like "unloadLibrary" ? ;)
 
S

Steve W. Jackson

:Hi. I'm using DLL through JNI. However, when I got an Exception before
:calling the DLL library, there is a "java.lang.UnsatisfiedLinkError: xxx.dll
:already loaded in another classloader". Of course, it wokrs perfectly when
:there is no Exception. How can I get this stuff work fine? Is there any
:method something like "unloadLibrary" ? ;)

There is no explicit way I know of to unload a library. But there may
be some alternatives.

This is purely speculation, as the library loaded in my app is in a
class that's going to exist for the life of the app. But it occurs to
wonder if the library would get unloaded when the class is garbage
collected. I have no idea whether that's true or not -- just a thought.

The other thought is to simply set a boolean someplace (perhaps a static
member variable in some class you can access from everywhere) indicating
that it's been loaded and thus prevent attempts from elsewhere.

= Steve =
 
R

Roedy Green

The other thought is to simply set a boolean someplace (perhaps a static
member variable in some class you can access from everywhere) indicating
that it's been loaded and thus prevent attempts from elsewhere.

you could also do the loadLibrary in a static init block.
Then it will get called only once.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top