org.zeroturnaround.exec.MDCCallableAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zt-exec Show documentation
Show all versions of zt-exec Show documentation
A lightweight library to execute external processes from Java.
package org.zeroturnaround.exec;
import java.util.Map;
import java.util.concurrent.Callable;
import org.slf4j.MDC;
/**
* Restores the MDC context map for the target action.
*/
public class MDCCallableAdapter implements Callable {
private final Callable target;
private final Map contextMap;
public MDCCallableAdapter(Callable target, Map contextMap) {
this.target = target;
this.contextMap = contextMap;
}
public T call() throws Exception {
MDC.setContextMap(contextMap);
try {
return target.call();
}
finally {
MDC.clear();
}
}
}