Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Thread-safe initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
matsjj committed Oct 27, 2020
1 parent 3cc9102 commit ac40869
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jni/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

group 'com.blockchain'
version '1.0.2'
version '1.0.3'

apply plugin: 'maven-publish'
apply plugin: 'maven'
Expand Down
27 changes: 19 additions & 8 deletions jni/java/wallet/core/java/AnySigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit ac40869

Please sign in to comment.