From 6273a58c3bc584e13da3ee9c88d7496620d72c6d Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Tue, 3 Sep 2019 17:47:57 +0200 Subject: [PATCH] Assign even more thread names at thread creation. --- .../main/java/bisq/core/app/SetupUtils.java | 44 +++++++++---------- .../src/main/java/bisq/monitor/Monitor.java | 38 +++++++--------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/bisq/core/app/SetupUtils.java b/core/src/main/java/bisq/core/app/SetupUtils.java index 3382eb6272..0edf297d2c 100644 --- a/core/src/main/java/bisq/core/app/SetupUtils.java +++ b/core/src/main/java/bisq/core/app/SetupUtils.java @@ -49,33 +49,29 @@ public class SetupUtils { // If users compile themselves they might miss that step and then would get an exception in the trade. // To avoid that we add here at startup a sample encryption and signing to see if it don't causes an exception. // See: https://github.com/bisq-network/exchange/blob/master/doc/build.md#7-enable-unlimited-strength-for-cryptographic-keys - Thread checkCryptoThread = new Thread() { - @Override - public void run() { - try { - Thread.currentThread().setName("checkCryptoThread"); - // just use any simple dummy msg - Ping payload = new Ping(1, 1); - SealedAndSigned sealedAndSigned = EncryptionService.encryptHybridWithSignature(payload, - keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey()); - DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned, - keyRing.getEncryptionKeyPair().getPrivate()); - if (tuple.getNetworkEnvelope() instanceof Ping && - ((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() && - ((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) { - log.debug("Crypto test succeeded"); + Thread checkCryptoThread = new Thread(() -> { + try { + // just use any simple dummy msg + Ping payload = new Ping(1, 1); + SealedAndSigned sealedAndSigned = EncryptionService.encryptHybridWithSignature(payload, + keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey()); + DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned, + keyRing.getEncryptionKeyPair().getPrivate()); + if (tuple.getNetworkEnvelope() instanceof Ping && + ((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() && + ((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) { + log.debug("Crypto test succeeded"); - UserThread.execute(resultHandler::handleResult); - } else { - errorHandler.accept(new CryptoException("Payload not correct after decryption")); - } - } catch (CryptoException | ProtobufferException e) { - log.error(e.toString()); - e.printStackTrace(); - errorHandler.accept(e); + UserThread.execute(resultHandler::handleResult); + } else { + errorHandler.accept(new CryptoException("Payload not correct after decryption")); } + } catch (CryptoException | ProtobufferException e) { + log.error(e.toString()); + e.printStackTrace(); + errorHandler.accept(e); } - }; + }, "checkCryptoThread"); checkCryptoThread.start(); } diff --git a/monitor/src/main/java/bisq/monitor/Monitor.java b/monitor/src/main/java/bisq/monitor/Monitor.java index da454b0a2f..5e7b8d19bc 100644 --- a/monitor/src/main/java/bisq/monitor/Monitor.java +++ b/monitor/src/main/java/bisq/monitor/Monitor.java @@ -21,11 +21,11 @@ import bisq.monitor.metric.MarketStats; import bisq.monitor.metric.P2PMarketStats; import bisq.monitor.metric.P2PNetworkLoad; import bisq.monitor.metric.P2PRoundTripTime; +import bisq.monitor.metric.P2PSeedNodeSnapshot; import bisq.monitor.metric.PriceNodeStats; import bisq.monitor.metric.TorHiddenServiceStartupTime; import bisq.monitor.metric.TorRoundTripTime; import bisq.monitor.metric.TorStartupTime; -import bisq.monitor.metric.P2PSeedNodeSnapshot; import bisq.monitor.reporter.ConsoleReporter; import bisq.monitor.reporter.GraphiteReporter; @@ -114,33 +114,29 @@ public class Monitor { configure(); // exit Metrics gracefully on shutdown - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - // set the name of the Thread for debugging purposes - setName("shutdownHook"); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + // set the name of the Thread for debugging purposes + log.info("system shutdown initiated"); - log.info("system shutdown initiated"); + log.info("shutting down active metrics..."); + Metric.haltAllMetrics(); - log.info("shutting down active metrics..."); - Metric.haltAllMetrics(); + try { + log.info("shutting down tor..."); + Tor tor = Tor.getDefault(); + checkNotNull(tor, "tor must not be null"); + tor.shutdown(); + } catch (Throwable ignore) { + } - try { - log.info("shutting down tor..."); - Tor tor = Tor.getDefault(); - checkNotNull(tor, "tor must not be null"); - tor.shutdown(); - } catch (Throwable ignore) { - } - - log.info("system halt"); - } - }); + log.info("system halt"); + }, "Monitor Shutdown Hook ") + ); } /** * Reload the configuration from disk. - * + * * @throws Exception if something goes wrong */ private void configure() throws Exception {