From 6c50d40444f3a857b50c807e11b934d3eb28c313 Mon Sep 17 00:00:00 2001 From: AhmedMaged Date: Sun, 4 May 2025 15:55:32 +0300 Subject: [PATCH 1/2] Terminate JVM of already running instances --- app/src/processing/app/Base.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index b5aa599b9..d7f887bba 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -324,6 +324,8 @@ static private void createAndShowGUI(String[] args) { // long t10 = System.currentTimeMillis(); // System.out.println("startup took " + (t2-t1) + " " + (t3-t2) + " " + (t4-t3) + " " + (t5-t4) + " " + (t6-t5) + " " + (t10-t6) + " ms"); + } else { + System.exit(0); } } From e8903a8c23c232e81e43f6310364e280657e56f0 Mon Sep 17 00:00:00 2001 From: AhmedMaged Date: Sun, 4 May 2025 18:38:25 +0300 Subject: [PATCH 2/2] making the code clearer --- app/src/processing/app/Base.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d7f887bba..ce78b4b6c 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -251,7 +251,16 @@ static private void createAndShowGUI(String[] args) { // long t2 = System.currentTimeMillis(); - if (DEBUG || !SingleInstance.alreadyRunning(args)) { + // boolean flag indicating whether to create new server instance or not + boolean createNewInstance = DEBUG || !SingleInstance.alreadyRunning(args); + + // free up resources by terminating the JVM + if(!createNewInstance){ + System.exit(0); + return; + } + + if (createNewInstance) { // Set the look and feel before opening the window try { Platform.setLookAndFeel(); @@ -324,8 +333,6 @@ static private void createAndShowGUI(String[] args) { // long t10 = System.currentTimeMillis(); // System.out.println("startup took " + (t2-t1) + " " + (t3-t2) + " " + (t4-t3) + " " + (t5-t4) + " " + (t6-t5) + " " + (t10-t6) + " ms"); - } else { - System.exit(0); } }