在weblogic中,sesion persitence有如下几种方式:
memory—Disables persistent session storage.
file—Uses file-based persistence (See also PersistentStoreDir, above).
jdbc—Uses a database to store persistent sessions. (see also PersistentStorePool, above).
replicated—Same as memory, but session data is replicated across the clustered servers.
cookie—All session data is stored in a cookie in the user's browser.
replicated_if_clustered—If the Web application is deployed on a clustered server, the in-effect PersistentStoreType will be replicated. Otherwise, memory is the default.
本文讨论的重点是持久化导致的性能问题,故只讨论JDBC和File两种方式,其余的不做讨论,Session相关的Params,请参考如下链接,
http://e-docs.bea.com/wls/docs81/webapp/weblogic_xml.html#1038173
首先说一下File persistence, 要使http session被写入到指定f目录下的file中,需要在/WEB-INF/weblogic.xml做如下配置:
weblogic.xml <session-param>
<param-name>PersistentStoreType</param-name>
<param-value>file</param-value>
</session-param>
<session-param>
<param-name>PersistentStoreDir</param-name>
<param-value>d:\session_test</param-value>
</session-param>
<session-param>
<param-name>CacheSize</param-name>
<param-value>10</param-value>
</session-param>
</session-descriptor>
测试我们使用weblogic自带的mainWebApp, 该web app位于类似如下的位置
D:\beasys\wls816\weblogic81\samples\server\examples\build
测试前,按上面的写法修改weblogic.xml, 然后修改index.jsp, 去掉头部的如下内容:
<%@ page session="false" %>
并修改其内容如下:
1 <%@ page import="java.util.ArrayList" %>
2 3 <%
4 String url = "http://" + request.getServerName() + ":" + request.getServerPort();
5 session.setAttribute("key", "value");
6 ArrayList list = new ArrayList();
7 for(int loop = 0; loop < 100000; loop++)
8 {
9 list.add("test" + loop);
10 }
11 session.setAttribute("list", list);
12 %>