Add Snappy.cleanUp method for J2EE containers. #27
This commit is contained in:
parent
2891c692c0
commit
a48529731d
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue