I have invalidated session in HandlerInterceptorAdapter
, Please refer the below code.
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception { request.getSession(false).invalidate();
log.debug ("Session Deleted after invalidate:" + request.getSession(false));
}
Here I am seeing null
in log. That means session is destroyed. Please correct me if I am wrong.
Now the problem is the PS Old Gen memory is growing, I have taken a dump from the server and I found there are lot of memory blocked by StandardSession
related objects.
In the above image ConcurrentHashMap
has lot of session id vs StandardSession
object data.
Can someone please explain me why this session objects are not cleared from the memory even after invalidating the session.
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
createSession();
return setupSession(request);
}
private void createSession() {
ServletRequestAttributes sra = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(sra != null){
HttpServletRequest req = sra.getRequest();
if(req != null){
HttpSession session = req.getSession(false);
if(session != null) {
log.debug("Invalidating old session");
session.invalidate();
}
session = req.getSession(true);
session.setAttribute(StrutsSettingsHandler.REQUEST_TYPE_REST_KEY,
StrutsSettingsHandler.REQUEST_TYPE_REST);
session.setMaxInactiveInterval(10);
log.debug ("New session created, Id = "+session.getId());
}
}
}