@@ -0,0 +1,2481 @@
+package org.jboss.threads;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.security.AccessController;%0Aimport java.security.PrivilegedAction;%0A%0A/**%0A * A direct executor which resets the thread-local maps after every task (if possible).%0A */%0Apublic class ResettingDirectExecutor implements DirectExecutor %7B%0A    private final DirectExecutor delegate;%0A%0A    private static final Field THREAD_LOCAL_MAP_FIELD;%0A    private static final Field INHERITABLE_THREAD_LOCAL_MAP_FIELD;%0A    private static final RuntimePermission MODIFY_THREAD_PERMISSION = new RuntimePermission(%22modifyThread%22);%0A%0A    static %7B%0A        THREAD_LOCAL_MAP_FIELD = AccessController.doPrivileged(new PrivilegedAction%3CField%3E() %7B%0A            public Field run() %7B%0A                final Field field;%0A                try %7B%0A                    field = Thread.class.getDeclaredField(%22threadLocals%22);%0A                    field.setAccessible(true);%0A                %7D catch (NoSuchFieldException e) %7B%0A                    return null;%0A                %7D%0A                return field;%0A            %7D%0A        %7D);%0A        INHERITABLE_THREAD_LOCAL_MAP_FIELD = AccessController.doPrivileged(new PrivilegedAction%3CField%3E() %7B%0A            public Field run() %7B%0A                final Field field;%0A                try %7B%0A                    field = Thread.class.getDeclaredField(%22threadLocals%22);%0A                    field.setAccessible(true);%0A                %7D catch (NoSuchFieldException e) %7B%0A                    return null;%0A                %7D%0A                return field;%0A            %7D%0A        %7D);%0A    %7D%0A%0A    /**%0A     * Construct a new instance.%0A     *%0A     * @param delegate the executor which will actually execute the task%0A     */%0A    public ResettingDirectExecutor(DirectExecutor delegate) %7B%0A        final SecurityManager sm = System.getSecurityManager();%0A        if (sm != null) %7B%0A            sm.checkPermission(MODIFY_THREAD_PERMISSION);%0A        %7D%0A        this.delegate = delegate;%0A    %7D%0A%0A    private static void clear(final Thread currentThread, final Field field) %7B%0A        try %7B%0A            field.set(currentThread, null);%0A        %7D catch (IllegalAccessException e) %7B%0A            // ignore%0A        %7D%0A    %7D%0A%0A    /** %7B@inheritDoc%7D */%0A    public void execute(Runnable command) %7B%0A        try %7B%0A            delegate.execute(command);%0A        %7D finally %7B%0A            final Thread thread = Thread.currentThread();%0A            clear(thread, THREAD_LOCAL_MAP_FIELD);%0A            clear(thread, INHERITABLE_THREAD_LOCAL_MAP_FIELD);%0A        %7D%0A    %7D%0A%7D%0A

Add direct executor which nukes threadlocals after the task is complete