I have a theory as to why I have the following problem, but I can't find any documentation proving my theory one way or another so I'd like some advice.
I have a (signed) applet which loads a DLL. Now, last Friday I was hitting "Refresh" and the applet was reloading fine, including apparently reloading the DLLs. But today, hitting "Refresh" is causing the following exception:
java.lang.UnsatisfiedLinkError: Native Library XXX already loaded in another classloader
According to the Javadoc (Java 6) System.loadLibrary is a convenience method for Runtime.loadLibrary and according to that documentation:
If this method is called more than once with the same library name, the second and subsequent calls are ignored.
I know and understand that you cannot load the same native library in different class loaders in the same JVM, which explains the above exception. What I'm trying to prove is why it seemed to work on one day, but now doesn't. Especially given that there has been no code changes at all around the DLL loading.
So my assumptions are this;
- The above documentation should read "the sec开发者_如何学编程ond and subsequent calls *in the same class loader* are ignored
- Last Friday, the planets were in a different alignment and so the browser was using a different JVM (or maybe the same class loader?) when I was hitting refresh, so the DLL was loaded properly and things worked nicely.
- Today the planets are aligned differently and the browser is reusing the same JVM but a different classloader and this explains why I'm getting this error now.
Incidentally, the browser in question was IE7 and I'm running Java 1.6. I don't think the browser version is particularly important since it's my understanding that what the browser decides to do with an applet is completely up to the browser implementer.
Do these assumptions seem reasonable and correct? What might I have missed?
Many thanks in advance.
It sounds like this Problem : Native Library already loaded in another classloader
Now they are talking about servlets, not applets, but many of the same behaviors apply.
Browsers tie the classloader to the url and possibly the socket connection. So, reloading would reuse the same class loader unless the browser sat long enough to idle out the connection at which point you get a new socket and hence a new class loader. We had multiple applets on the same page and it was a crap shoot whether they would share a class loader following a reload of the page.
精彩评论