在春季的HTTP请求之后,我们是否需要清除MDC
根据这个答案线程局部变量,当我们使用线程局部时,我们应该清除线程池环境中的所有变量。
所以基本上我只想确认,当我们使用MDC(映射的诊断上下文)时,我们也应该清除MDC以感知内存泄漏,这是真的吗?
例如:
@Configuration
public class WebConfig implements WebMvcConfigurer {
public class HttpInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(final HttpServletRequest request,
final HttpServletResponse response,
final Object handler) {
MDC.put(SESSION_ID, session_id);
{
@Override
public void postHandle(final HttpServletRequest request,
final HttpServletResponse response,
final Object handler,
final ModelAndView modelAndView) {
MDC.clear(); //WE SHOULD CLEAR MDC.... if not memory leaks ?
}
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MdcHandlerInterceptor());
}
}