Add Snappy.cleanUp method for J2EE containers. #27

This commit is contained in:
Taro L. Saito 2013-08-13 16:07:46 +09:00
parent 2891c692c0
commit a48529731d
2 changed files with 24 additions and 4 deletions

View File

@ -56,6 +56,19 @@ public class Snappy
*/
private static SnappyNative impl;
/**
* Clean up a temporary file (native lib) generated by snappy-java.
* General users do not need to call this method, since the native library extracted in snappy-java
* is deleted upon JVM termination (vie deleteOnExit()).
* This method is useful when using a J2EE container, which will restart servlet containers multiple times without
* restarting JVM.
*/
static void cleanUp() {
SnappyLoader.cleanUpExtractedNativeLib();
}
/**
* Copy bytes from source to destination
*

View File

@ -82,7 +82,14 @@ public class SnappyLoader
private static volatile boolean isLoaded = false;
private static volatile SnappyNative api = null;
private static File nativeLibFile = null;
static void cleanUpExtractedNativeLib() {
if(nativeLibFile != null && nativeLibFile.exists())
nativeLibFile.delete();
}
/**
* Set the api instance.
*
@ -153,10 +160,10 @@ public class SnappyLoader
*/
private static void loadNativeLibrary() {
File nativeLib = findNativeLibrary();
if (nativeLib != null) {
nativeLibFile = findNativeLibrary();
if (nativeLibFile != null) {
// Load extracted or specified snappyjava native library.
System.load(nativeLib.getAbsolutePath());
System.load(nativeLibFile.getAbsolutePath());
}
else {
// Load preinstalled snappyjava (in the path -Djava.library.path)