This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-121
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-121 by this push:
new a991ab1 For for NLPCRAFT-121.
a991ab1 is described below
commit a991ab19fbe4f6fa6557d6eef8edccf91f83e7dd
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Sep 13 20:32:18 2020 -0700
For for NLPCRAFT-121.
---
.../org/apache/nlpcraft/common/util/NCUtils.scala | 9 +++++++++
.../scala/org/apache/nlpcraft/probe/NCProbeBoot.scala | 19 ++++++++++++++-----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index 226d48e..05db312 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -1151,6 +1151,15 @@ object NCUtils extends LazyLogging {
}
/**
+ * Interrupts thread.
+ *
+ * @param t Thread.
+ */
+ def interruptThread(t: Thread): Unit =
+ if (t != null)
+ t.interrupt()
+
+ /**
* Shuts down executor services and waits for their finish.
*
* @param ess Executor services.
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
index 02eadbe..8f461b3 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -182,7 +182,11 @@ private [probe] object NCProbeBoot extends LazyLogging
with NCOpenCensusTrace {
case _ ⇒ // Managers started OK.
shutdownHook = new Thread() {
- override def run(): Unit = stop0()
+ override def run(): Unit = {
+ logger.info("Executing shutdown hook...")
+
+ stop0()
+ }
}
Runtime.getRuntime.addShutdownHook(shutdownHook)
@@ -191,8 +195,6 @@ private [probe] object NCProbeBoot extends LazyLogging with
NCOpenCensusTrace {
started = true
- fut.complete(0)
-
// Wait indefinitely.
while (started)
try
@@ -200,6 +202,8 @@ private [probe] object NCProbeBoot extends LazyLogging with
NCOpenCensusTrace {
catch {
case _: InterruptedException ⇒ ()
}
+
+ fut.complete(0)
}
logger.trace("Probe thread stopped OK.")
@@ -218,7 +222,7 @@ private [probe] object NCProbeBoot extends LazyLogging with
NCOpenCensusTrace {
started = false
- U.stopThread(probeThread)
+ U.interruptThread(probeThread)
logger.info("Probe shutdown OK.")
}
@@ -442,7 +446,12 @@ private [probe] object NCProbeBoot extends LazyLogging
with NCOpenCensusTrace {
*/
private def stopManagers(): Unit = {
startScopedSpan("stopManagers") { span ⇒
- startedMgrs.reverseIterator.foreach(_.stop(span))
+ startedMgrs.synchronized {
+ try
+ startedMgrs.reverseIterator.foreach(_.stop(span))
+ finally
+ startedMgrs.clear()
+ }
}
// Lifecycle callback outside of tracing span.