From faa8bd2ab290c365d1f473b63f27bca181e843d5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 10 Nov 2021 12:26:54 +0100 Subject: [PATCH 1/3] Extract code in CommonSetup which uses a timer to startPeriodicTasks. Call that from BisqExecutable.onApplicationLaunched We have created a non-UI timer before for the printSystemLoadPeriodically as that was called before the configUserThread was called (where we define the UI timer for desktop) --- common/src/main/java/bisq/common/setup/CommonSetup.java | 8 +++++--- core/src/main/java/bisq/core/app/BisqExecutable.java | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index cc23cf5f6c5..0ab19dab310 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -55,19 +55,21 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown Version.printVersion(); maybePrintPathOfCodeSource(); Profiler.printSystemLoad(); - Profiler.printSystemLoadPeriodically(10, TimeUnit.MINUTES); // Full DAO nodes (like seed nodes) do not use the GC triggers as it is expected they have sufficient RAM allocated. GcUtil.setDISABLE_GC_CALLS(config.fullDaoNode); - GcUtil.autoReleaseMemory(); - setSystemProperties(); setupSigIntHandlers(gracefulShutDownHandler); DevEnv.setup(config); } + public static void startPeriodicTasks() { + Profiler.printSystemLoadPeriodically(10, TimeUnit.MINUTES); + GcUtil.autoReleaseMemory(); + } + public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) { Thread.UncaughtExceptionHandler handler = (thread, throwable) -> { // Might come from another thread diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 0ab2895819f..3e8fdc587f1 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -130,8 +130,13 @@ protected void addCapabilities() { /////////////////////////////////////////////////////////////////////////////////////////// // Headless versions can call inside launchApplication the onApplicationLaunched() manually + // Desktop gets called from JavaFx thread protected void onApplicationLaunched() { configUserThread(); + + // Now we can use the user thread start periodic tasks + CommonSetup.startPeriodicTasks(); + // As the handler method might be overwritten by subclasses and they use the application as handler // we need to setup the handler after the application is created. CommonSetup.setupUncaughtExceptionHandler(this); From 880df30ffc73856ee789a92a1f6ed9bca9df70ac Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 10 Nov 2021 12:27:50 +0100 Subject: [PATCH 2/3] Remove unneeded UserThread.execute wrappers In desktop we are on the UI thread. In Seednode we have an outer UserThread.execute call already --- desktop/src/main/java/bisq/desktop/app/BisqAppMain.java | 4 ++-- seednode/src/main/java/bisq/seednode/SeedNodeMain.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java index d2577194db9..a875e83ca66 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java @@ -73,8 +73,8 @@ protected void configUserThread() { protected void launchApplication() { BisqApp.setAppLaunchedHandler(application -> { BisqAppMain.this.application = (BisqApp) application; - // Map to user thread! - UserThread.execute(this::onApplicationLaunched); + + onApplicationLaunched(); }); Application.launch(BisqApp.class); diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 080aff96d21..0ab48ccacd5 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -75,11 +75,11 @@ protected void addCapabilities() { } @Override - protected void launchApplication() { + protected void launchApplication() {//todo UserThread.execute(() -> { try { seedNode = new SeedNode(); - UserThread.execute(this::onApplicationLaunched); + onApplicationLaunched(); } catch (Exception e) { e.printStackTrace(); } From 40ad5737cb7f16a144ac0ad66d21885353c6449a Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 10 Nov 2021 13:21:56 +0100 Subject: [PATCH 3/3] Remove unnecessary todo --- seednode/src/main/java/bisq/seednode/SeedNodeMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 0ab48ccacd5..5bfb17ceff6 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -75,7 +75,7 @@ protected void addCapabilities() { } @Override - protected void launchApplication() {//todo + protected void launchApplication() { UserThread.execute(() -> { try { seedNode = new SeedNode();