memcached(十一)memcached-session-manager

[size=xx-large]介绍[/size]
memcached-session-manager是将tomcat中的session,托管到memcache中管理,实现tomcat的无状态应用。
但是在笔者的经验中,我们一般开发的时候,不会使用这个技术。而是将现有的项目中使用了session,快速升级为无状态应用时,会使用这种办法。

相关官方
https://code.google.com/p/memcached-session-manager/downloads/list
http://javolution.org/
http://www.couchbase.com/develop/java/current

详细教程
http://blog.csdn.net/ichsonx/article/details/6911358
http://www.iteye.com/topic/1125301

附件是本教程用到的lib包

[size=xx-large]tomcat7的安装[/size]
将附件中的全部jar拷贝到${tomcat_home}/lib目录下,
注意:工程目录不能有这些JAR包

修改工程目录下META-INF/context.xml或者${tomcat_home}/conf/server.xml下的context节点,增加
                                   memcachedNodes="n1:192.168.56.2:11211"      
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js|ico)$"
sessionBackupAsync="false"
sessionBackupTimeout="100"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
copyCollectionsForSerialization="false"
/>


[size=xx-large]测试[/size]
用2个浏览器打开即可,首先用chrome打开,然后用火狐打开。查看jsessionid是否一致。
JSP测试代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>




Insert title here


<%
String tmp = (String)session.getAttribute("tmp");
if(tmp == null || tmp == ""){
session.setAttribute("tmp","i am created in tomcat 2 . my id is : "+session.getId());
tmp = (String)session.getAttribute("tmp");
out.println(" null now to created value !");
out.println("
");
out.println(tmp);
System.out.println(tmp);
}else{
out.println(tmp);
System.out.println(tmp);
}
%>




参考教程
http://blog.csdn.net/ichsonx/article/details/6911358
http://www.iteye.com/topic/1125301


相关官方
https://code.google.com/p/memcached-session-manager/downloads/list
http://javolution.org/
http://www.couchbase.com/develop/java/current

你可能感兴趣的:(memcached(十一)memcached-session-manager)