File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UnsatisfiedLinkError when using custom ClassLoader

 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a really good problem here. Hopefully there is an expert out there that can help me figure it out or already has the answer.
I have built a custom ClassLoader extending the java.lang.ClassLoader. I use this ClassLoader (not important why I need it) to load a class X. This class X uses some native methods, so I load the dll with System.load("blah.dll"); inside Class X. Everything seems to work fine when I load class X, but intermittently I get an "UnsatisfiedLinkError: Native library <blah.dll> already loaded in another ClassLoader." There does not seem to be a pattern as to when this happens. Sometimes I can load class X 20 times before this happens, and sometimes only a few times. It's very strange. Is there a way to check if a dll is already loaded before trying to load it? I suppose I could catch the UnsatifiedLinkException, but then I don't know what to do once I've caught it. I could probably load the dll once at the beginning of the program, but I would like the load to happen inside class X for a more OO approach. Anyway, if anyone has any suggestions, I would love to hear.
Many many thanks!!
Barry
P.S. If I let JVM handle class loading, I don't get this problem at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic