InternalThreadLocal { @SuppressWarnings("unchecked") public static void removeAll() { InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.getIfSet(); if (threadLocalMap == null) { return; } try { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); if (v != null && v != InternalThreadLocalMap.UNSET) { Set<InternalThreadLocal<?>> variablesToRemove = (Set<InternalThreadLocal<?>>) v; InternalThreadLocal<?>[] variablesToRemoveArray = variablesToRemove.toArray(new InternalThreadLocal[variablesToRemove.size()]); for (InternalThreadLocal<?> tlv : variablesToRemoveArray) { tlv.remove(threadLocalMap); } } } finally { InternalThreadLocalMap.remove(); } } InternalThreadLocal(); @SuppressWarnings("unchecked") static void removeAll(); static int size(); static void destroy(); @SuppressWarnings("unchecked") final V get(); final void set(V value); @SuppressWarnings("unchecked") final void remove(); @SuppressWarnings("unchecked") final void remove(InternalThreadLocalMap threadLocalMap);  }
@Test public void testRemoveAll() throws InterruptedException { final InternalThreadLocal<Integer> internalThreadLocal = new InternalThreadLocal<Integer>(); internalThreadLocal.set(1); Assert.assertTrue("set failed", internalThreadLocal.get() == 1); final InternalThreadLocal<String> internalThreadLocalString = new InternalThreadLocal<String>(); internalThreadLocalString.set("value"); Assert.assertTrue("set failed", "value".equals(internalThreadLocalString.get())); InternalThreadLocal.removeAll(); Assert.assertTrue("removeAll failed!", internalThreadLocal.get() == null); Assert.assertTrue("removeAll failed!", internalThreadLocalString.get() == null); }