From 56f7aa3b6a45d4309cc2c77fcac7e6fda5f45e55 Mon Sep 17 00:00:00 2001 From: vlad Date: Wed, 8 Nov 2017 04:09:28 -0800 Subject: App initialization convenience methods --- .../xyz/driver/core/logging/MdcExecutionContext.scala | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/main/scala/xyz/driver/core/logging') diff --git a/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala b/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala index 9f8db3e..f39f31d 100644 --- a/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala +++ b/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala @@ -13,17 +13,14 @@ import scala.concurrent.ExecutionContext class MdcExecutionContext(executionContext: ExecutionContext) extends ExecutionContext { override def execute(runnable: Runnable): Unit = { val callerMdc = MDC.getCopyOfContextMap - executionContext.execute(new Runnable { - def run(): Unit = { - // copy caller thread diagnostic context to execution thread - // scalastyle:off - if (callerMdc != null) MDC.setContextMap(callerMdc) - try { - runnable.run() - } finally { - // the thread might be reused, so we clean up for the next use - MDC.clear() - } + executionContext.execute(() => { + // copy caller thread diagnostic context to execution thread + Option(callerMdc).foreach(MDC.setContextMap) + try { + runnable.run() + } finally { + // the thread might be reused, so we clean up for the next use + MDC.clear() } }) } -- cgit v1.2.3