From ac408691815107264da6eaa76598397332b68844 Mon Sep 17 00:00:00 2001 From: Mats Jerratsch Date: Mon, 27 Apr 2020 11:46:23 +0100 Subject: [PATCH] Thread-safe initialisation --- jni/build.gradle | 2 +- jni/java/wallet/core/java/AnySigner.java | 27 +++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/jni/build.gradle b/jni/build.gradle index 8794f9a428c..9b97e077ce0 100644 --- a/jni/build.gradle +++ b/jni/build.gradle @@ -15,7 +15,7 @@ plugins { } group 'com.blockchain' -version '1.0.2' +version '1.0.3' apply plugin: 'maven-publish' apply plugin: 'maven' diff --git a/jni/java/wallet/core/java/AnySigner.java b/jni/java/wallet/core/java/AnySigner.java index 734225cff7a..de05cd2ba10 100644 --- a/jni/java/wallet/core/java/AnySigner.java +++ b/jni/java/wallet/core/java/AnySigner.java @@ -25,14 +25,25 @@ public class AnySigner { private static boolean isInitialized = false; public static void initialize() { - // Load the static library from the resource path somehow... - try { - tempDirWithPrefix = Files.createTempDirectory(tempFolderPrefix); - String resourceName = getResourceName(); - String resourcePath = writeResourceToFile(resourceName); - System.load(resourcePath); - } catch (Exception e) { - e.printStackTrace(); + if(isInitialized) { + return; + } + + synchronized (tempFolderPrefix) { + if(isInitialized) { + return; + } + + // Load the static library from the resource path somehow... + try { + tempDirWithPrefix = Files.createTempDirectory(tempFolderPrefix); + String resourceName = getResourceName(); + String resourcePath = writeResourceToFile(resourceName); + System.load(resourcePath); + } catch (Exception e) { + System.out.println("Unable to load static library, " + e.getMessage()); + e.printStackTrace(); + } } }