From 3502d780735b537f29ec398745a7ed264805ac9b Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Thu, 3 Mar 2022 11:33:59 +0800 Subject: bugfix - fixed the healthcheck problem Issue-ID: HOLMES-512 Signed-off-by: GuangrongFu Change-Id: I4393c649468157c00f3ea57568056b087b76554c --- .../java/org/onap/holmes/rulemgt/Initializer.java | 19 +++++++++++-------- .../java/org/onap/holmes/rulemgt/InitializerTest.java | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'rulemgt/src') diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java index 812ee48..3995e4c 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java @@ -30,6 +30,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static org.onap.holmes.common.utils.CommonUtils.getEnv; @@ -38,7 +39,7 @@ import static org.onap.holmes.common.utils.CommonUtils.isIpAddress; @Service public class Initializer { private static final Logger logger = LoggerFactory.getLogger(Initializer.class); - private static boolean readyForMsbReg = false; + private volatile static boolean readyForMsbReg = false; private MsbRegister msbRegister; @Inject @@ -48,17 +49,19 @@ public class Initializer { @PostConstruct private void init() { - waitUntilReady(); - try { - msbRegister.register2Msb(createMicroServiceInfo()); - } catch (CorrelationException e) { - logger.error(e.getMessage(), e); - } + Executors.newSingleThreadExecutor().execute(() -> { + waitUntilReady(); + try { + msbRegister.register2Msb(createMicroServiceInfo()); + } catch (CorrelationException e) { + logger.error(e.getMessage(), e); + } + }); } private void waitUntilReady() { int count = 1; - while(!readyForMsbReg) { + while (!readyForMsbReg) { if (count > 20) { break; } diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java index f658d35..8e4a6fe 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java @@ -51,6 +51,8 @@ public class InitializerTest { WhiteboxImpl.invokeMethod(initializer, "init"); + TimeUnit.SECONDS.sleep(6); + PowerMock.verifyAll(); } -- cgit 1.2.3-korg