title: Reloading DLLs in an Applet in a Browser
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>java.lang.UnsatisfiedLinkError: Native Library XXX already loaded in another classloader
  </code></pre>
  
  <p>According to the Javadoc (Java 6) System.loadLibrary is a convenience method for Runtime.loadLibrary and according to that documentation:</p>
  
  <blockquote>
    <p>If this method is called more than once with the same library name, the second and subsequent calls are ignored.</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>So my assumptions are this;</p>
  
  <ol>
  <li>The above documentation should read "the second and subsequent calls *in the same class loader* are ignored</li>
  <li>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.</li>
  <li>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.</li>
  </ol>
  
  <p>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.</p>
  
  <p>Do these assumptions seem reasonable and correct?  What might I have missed?</p>
  
  <p>Many thanks in advance.</p>