diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 84e9c914..6d17a439 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -893,6 +893,7 @@ public class AppController implements Initializable { Storage storage = new Storage(file); if(!storage.isEncrypted()) { Storage.LoadWalletService loadWalletService = new Storage.LoadWalletService(storage); + loadWalletService.setExecutor(Storage.LoadWalletService.getSingleThreadedExecutor()); loadWalletService.setOnSucceeded(workerStateEvent -> { WalletAndKey walletAndKey = loadWalletService.getValue(); openWallet(storage, walletAndKey, this, forceSameWindow); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index bc95992a..5dee1efc 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -8,6 +8,7 @@ import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.sparrow.MainApp; import javafx.concurrent.Service; import javafx.concurrent.Task; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.controlsfx.tools.Platform; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,6 +23,8 @@ import java.security.cert.CertificateEncodingException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -509,6 +512,8 @@ public class Storage { private final Storage storage; private final SecureString password; + private static Executor singleThreadedExecutor; + public LoadWalletService(Storage storage) { this.storage = storage; this.password = null; @@ -536,6 +541,15 @@ public class Storage { } }; } + + public static Executor getSingleThreadedExecutor() { + if(singleThreadedExecutor == null) { + BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("LoadWalletService-single").daemon(true).priority(Thread.MIN_PRIORITY).build(); + singleThreadedExecutor = Executors.newSingleThreadScheduledExecutor(factory); + } + + return singleThreadedExecutor; + } } public static class KeyDerivationService extends Service {