MdcThreadPoolExecutor extends ThreadPoolExecutor { @Override public void execute(Runnable command) { super.execute(wrap(command, MDC.getCopyOfContextMap())); } MdcThreadPoolExecutor(int corePoolSize,
                                 int maximumPoolSize,
                                 long keepAliveTime,
                                 TimeUnit unit,
                                 BlockingQueue<Runnable> workQueue,
                                 ThreadFactory threadFactory,
                                 RejectedExecutionHandler rejectedExecutionHandler); @Override void execute(Runnable command); static Runnable wrap(final Runnable runnable, final Map<String, String> context);  }
@Test(timeout = 1000) public void testExecute() throws Exception { MDC.put("foo", "bar"); threadPoolExecutor.execute(() -> { Assert.assertEquals("bar", MDC.get("foo")); getThroughRunnable = true; }); Thread.sleep(500); Assert.assertTrue(getThroughRunnable); }