Skip to content

Commit 67f5ac8

Browse files
authored
ARROW-17794: [Java] Force delete jni lib file on JVM exit (apache#14189)
Use `File.deleteOnExit` to delete jni lib file on JVM exit. `File.deleteOnExit` actually add a shut down hook to make sure file delte. Authored-by: jackylee-ch <lijunqing@baidu.com> Signed-off-by: David Li <li.davidm96@gmail.com>
1 parent be30611 commit 67f5ac8

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

‎java/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private void load(String name) {
8181
final String libraryToLoad = System.mapLibraryName(name);
8282
try {
8383
File temp = File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir")));
84+
temp.deleteOnExit();
8485
try (final InputStream is = JniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) {
8586
if (is == null) {
8687
throw new FileNotFoundException(libraryToLoad);

‎java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniLoader.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private void load(String name) {
7979
final String libraryToLoad = System.mapLibraryName(name);
8080
try {
8181
File temp = File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir")));
82+
temp.deleteOnExit();
8283
try (final InputStream is
8384
= JniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) {
8485
if (is == null) {

0 commit comments

Comments
 (0)