Fedor Belov commented on Bug LOGBACK-422

Solved this problem using Lóránt Pintér's suggestion. Here is my groovy version:

abstract class MdcRetainingCallable<V> implements Callable {
    private final Map context

    MdcRetainingCallable() {
        this.context = MDC.getCopyOfContextMap()
    }

    @Override
    V call() {
        V answer = null
        Map originalContext = MDC.getCopyOfContextMap()
        MDC.setContextMap(context);

        try {
            answer = withMdc();
        } finally {
            MDC.setContextMap(originalContext);
        }

        return answer
    }

    abstract protected V withMdc();

    static MdcRetainingCallable cast(Closure c) {
        return ([withMdc: c] as MdcRetainingCallable)
    }
}

When I need to submit task to executorService I do following

threadPool.submit(MdcRetainingCallable.cast { my_task_code })
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira