From f9ae3ab7680c6e6b56332b27fceab0c74503f35f Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Thu, 8 Feb 2024 16:53:20 +0400 Subject: [PATCH] [RM-84612] corrected after review --- .../com/exactpro/th2/hand/Application.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/exactpro/th2/hand/Application.java b/src/main/java/com/exactpro/th2/hand/Application.java index 6a0560d..d110673 100644 --- a/src/main/java/com/exactpro/th2/hand/Application.java +++ b/src/main/java/com/exactpro/th2/hand/Application.java @@ -40,18 +40,19 @@ public long getCurrentTime() { public void run(String[] args) { try (CommonFactory factory = CommonFactory.createFromArguments(args)) { Config config = getConfig(factory); - final HandServer handServer = new HandServer(config, getCurrentTime()); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - LOGGER.info("*** Closing hand server because JVM is shutting down"); - try { - handServer.close(); - } catch (InterruptedException e) { - LOGGER.warn("Server termination await was interrupted", e); - } - LOGGER.info("*** hand server closed"); - })); - handServer.start(); - handServer.blockUntilShutdown(); + try (HandServer handServer = new HandServer(config, getCurrentTime())) { + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + LOGGER.info("*** Closing hand server because JVM is shutting down"); + try { + handServer.close(); + } catch (InterruptedException e) { + LOGGER.warn("Server termination await was interrupted", e); + } + LOGGER.info("*** hand server closed"); + })); + handServer.start(); + handServer.blockUntilShutdown(); + } } catch (Exception e) { LOGGER.error("Could not to start Hand server", e); closeApp();