Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

UnsatisfiedLinkError when using custom ClassLoader  RSS feed

Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • 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!!
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
Boost this thread!