[英]What is the maximum number of HttpSession attributes
我们可以使用HttpSession保存多少个属性,
session.setAttribute("someName", "abc");
有没有限制? 我们可以在会话中保存n个属性吗?
我认为没有限制,这取决于您的计算机内存。
在此方法的文档中,与限制无关。
我有4 GB RAM。 我正在Tomcat 7上运行应用程序。
还设置-Xms512M -Xmx1524M参数。
我能够在HttpSession中设置并获取1,00,00,000个属性。
//WORKING CODE
for(Long i=1L; i<=10000000L; i++) {
request.getSession().setAttribute("TXN_"+i, i);
}
for(Long i=1L; i<=10000000L; i++) {
logger.info(request.getSession().getAttribute("TXN_"+i).toString());
}
//Below code causes OutOfMemory Error (Heap Space)
for(Long i=1L; i<=100000000L; i++) {
request.getSession().setAttribute("TXN_"+i, i);
}
for(Long i=1L; i<=100000000L; i++) {
logger.info(request.getSession().getAttribute("TXN_"+i).toString());
}
在HttpSession中保存1,00,00,000个属性对我的应用程序来说绰绰有余。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.