注意: 閱讀下文前,建議去看下JCP的Servlet規範。java
圖1 HttpSession接口web
能夠經過setAttribute方法在HttpSession中設置屬性,那麼有個問題,web容器中,底層上這個HttpSession的數據結構是什麼?安全
Tomcat-8.0.0中,有個StandardSession實現了HttpSession,這個StandardSession中有個attributes屬性,以下List-1所示,底層上用ConcurrentHashMap來做爲HttpSession的底層數據結構,保證併發操做的線程安全。數據結構
List-1 併發
/** * The collection of user data attributes associated with this Session. */ protected Map<String, Object> attributes = new ConcurrentHashMap<>();
invalidate方法,是指清空HttpSession中的全部數據,即在Tomcat-8.0.0中,清空底層attributes中的全部數據。this