ThreadLocalPropagateContext { public static Runnable wrap(Runnable task) { return new CopyThreadLocalRunnable(task); } private  ThreadLocalPropagateContext(); static void addThreadLocal(ThreadLocal<?> threadLocal); static ThreadLocal<?>[] getThreadLocals(); static void removeThreadLocal(ThreadLocal<?> threadLocal); void clear(); static Runnable wrap(Runnable task); static Callable<T> wrap(Callable<? extends T> task);  }
@Test public void testRunnableWithThreadLocalPropagateContext() throws Exception { final String[] holder = new String[1]; exec.submit(ThreadLocalPropagateContext.wrap(new Runnable() { @Override public void run() { holder[0] = tl1.get(); } })).get(); Assert.assertEquals(holder[0], tlValue); }
@Test public void testCallableWithThreadLocalPropagateContext() throws Exception { final String v = exec.submit(ThreadLocalPropagateContext.wrap(new Callable<String>() { @Override public String call() { return tl1.get(); } })).get(); Assert.assertEquals(v, tlValue); }
@Test public void testRunnableWithThreadLocalPropagateContext() throws Exception { final String[] holder = new String[1]; exec.submit( ThreadLocalPropagateContext.wrap( new Runnable() { @Override public void run() { holder[0] = tl1.get(); } })) .get(); Assert.assertEquals(holder[0], tlValue); }
@Test public void testCallableWithThreadLocalPropagateContext() throws Exception { final String v = exec.submit( ThreadLocalPropagateContext.wrap( new Callable<String>() { @Override public String call() { return tl1.get(); } })) .get(); Assert.assertEquals(v, tlValue); }