diff options
author | Omair Majid <[email protected]> | 2010-10-20 09:49:01 -0400 |
---|---|---|
committer | Omair Majid <[email protected]> | 2010-10-20 09:49:01 -0400 |
commit | 3ebd3fb0788bb8433902274370de97254b17e3d8 (patch) | |
tree | 96dcc2176db5b5fd5ea86d62bb08933e7ab2a6c7 /netx/net/sourceforge/jnlp | |
parent | c2783ee992baf5f0598f3125579a73b51ed51ed4 (diff) |
avoid creating unecessary nativedirs; clean them on exit
2010-10-20 Omair Majid <[email protected]>
* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
(JNLPClassLoader): Call installShutdownHooks.
(installShutdownHooks): New method. Installs a shutdown hook to
recursively delete the contents of nativeDir.
(activateNative): Only create a nativeDir if there are native
libraries.
Diffstat (limited to 'netx/net/sourceforge/jnlp')
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java index 972eb25..03c44a1 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -59,6 +59,7 @@ import net.sourceforge.jnlp.cache.ResourceTracker; import net.sourceforge.jnlp.cache.UpdatePolicy; import net.sourceforge.jnlp.security.SecurityWarningDialog; import net.sourceforge.jnlp.tools.JarSigner; +import net.sourceforge.jnlp.util.FileUtils; import sun.misc.JarIndex; /** @@ -169,6 +170,41 @@ public class JNLPClassLoader extends URLClassLoader { setSecurity(); + installShutdownHooks(); + + } + + /** + * Install JVM shutdown hooks to clean up resources allocated by this + * ClassLoader. + */ + private void installShutdownHooks() { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + if (JNLPRuntime.isDebug()) { + System.out.println("Cleaning up native directory" + nativeDir.getAbsolutePath()); + } + + /* + * Delete only the native dir created by this classloader (if + * there is one). Other classloaders (parent, peers) will all + * cleanup things they created + */ + if (nativeDir != null) { + try { + FileUtils.recursiveDelete(nativeDir, + new File(System.getProperty("java.io.tmpdir"))); + } catch (IOException e) { + /* + * failed to delete a file in tmpdir, no big deal (not + * to mention that the VM is shutting down at this + * point so no much we can do) + */ + } + } + } + }); } private void setSecurity() throws LaunchException { @@ -741,9 +777,6 @@ public class JNLPClassLoader extends URLClassLoader { if (localFile == null) return; - if (nativeDir == null) - nativeDir = getNativeDir(); - String[] librarySuffixes = { ".so", ".dylib", ".jnilib", ".framework", ".dll" }; try { @@ -770,10 +803,14 @@ public class JNLPClassLoader extends URLClassLoader { continue; } + if (nativeDir == null) + nativeDir = getNativeDir(); + File outFile = new File(nativeDir, name); CacheUtil.streamCopy(jarFile.getInputStream(e), new FileOutputStream(outFile)); + } } catch (IOException ex) { |