code: public static Runnable withMDC(Runnable r) {
      return new Runnable() {
  
        private final Map<String, String> contextMap = safeCopyOfContextMap();
  
        @Override
        public void run() {
          safeSetContextMap(contextMap);
          try {
            r.run();
          } finally {
            safeResetContextMap();
          }
        }
      };
    }
docs: Wrap a {@link Runnable} to use the {@link MDC} from the calling thread.