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/MdcExecutionContext.scala') 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 From 92eb152fd61f381ae39e2887fcec4a564b06b058 Mon Sep 17 00:00:00 2001 From: vlad Date: Wed, 8 Nov 2017 04:18:44 -0800 Subject: App initialization convenience methods --- .../xyz/driver/core/logging/MdcExecutionContext.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala') diff --git a/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala b/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala index f39f31d..df21b48 100644 --- a/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala +++ b/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala @@ -13,14 +13,16 @@ import scala.concurrent.ExecutionContext class MdcExecutionContext(executionContext: ExecutionContext) extends ExecutionContext { override def execute(runnable: Runnable): Unit = { val callerMdc = MDC.getCopyOfContextMap - 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() + executionContext.execute(new Runnable { + def run(): Unit = { + // 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