注意: 阅读下文前,建议去看下JCP的Servlet规范。
图1 HttpSession接口
可以通过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中的所有数据。
(adsbygoogle = window.adsbygoogle || []).push({});