This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 986c5cea40 Hopserver shutdown test sometimes fails  #7513 (#7514)
986c5cea40 is described below

commit 986c5cea40937c77a9917572fad2163ff69f08ae
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Mon Jul 13 15:47:01 2026 +0200

    Hopserver shutdown test sometimes fails  #7513 (#7514)
---
 .../java/org/apache/hop/www/ShutdownServlet.java   | 31 ++++++++++++++--------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/engine/src/main/java/org/apache/hop/www/ShutdownServlet.java 
b/engine/src/main/java/org/apache/hop/www/ShutdownServlet.java
index 51b33e0bcb..4fb9ba3aea 100644
--- a/engine/src/main/java/org/apache/hop/www/ShutdownServlet.java
+++ b/engine/src/main/java/org/apache/hop/www/ShutdownServlet.java
@@ -28,6 +28,9 @@ public class ShutdownServlet extends BaseHttpServlet {
 
   public static final String CONTEXT_PATH = "/shutdown";
 
+  /** Delay before the shutdown is performed, to give the servlet time to 
respond. */
+  private static final long SHUTDOWN_DELAY_MS = 2000L;
+
   @Override
   protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
       throws ServletException, IOException {
@@ -38,19 +41,25 @@ public class ShutdownServlet extends BaseHttpServlet {
             + "' at address "
             + request.getRemoteAddr());
 
-    TimerTask task =
-        new TimerTask() {
-          public void run() {
-            //  Gracefully shutdown the web server
-            HopServer server = HopServerSingleton.getHopServer();
-            if (server != null) {
-              server.shutdown();
+    HopServer server = HopServerSingleton.getHopServer();
+    if (server != null) {
+      Timer timer = new Timer("Server shutdown timer");
+      TimerTask task =
+          new TimerTask() {
+            @Override
+            public void run() {
+              try {
+                //  Gracefully shutdown the web server
+                server.shutdown();
+              } finally {
+                timer.cancel();
+              }
             }
-          }
-        };
+          };
 
-    // Delay shutdown to give servlet time to respond
-    new Timer("Server shutdown timer").schedule(task, 2000L);
+      // Delay shutdown to give servlet time to respond
+      timer.schedule(task, SHUTDOWN_DELAY_MS);
+    }
     response.setStatus(HttpServletResponse.SC_OK);
   }
 }

Reply via email to