According to this answer thread local variable when we use thread local we should clear all variable in thread pool environment.
So basically I just want to confirm that when we are using MDC (Mapped diagnostic context) we also should clear MDC to aware memory leaks, is that true ?
So for instance :
@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());
}
}