这里先说明下环境:JDK1.6、ehcache-core-2.1.0.jar、Tomcat6、Spring3.0.2。使用的是RMI方式配置集群的,这里先吐槽下遇到的情况,在搜相关知识的时候发现到处都是同一篇文章,被抄来抄去,最后没办法只好用英文在google上搜索才找到了大量有用的文章以及遇到类似的帖子,哎,继续写我的配置。(出自博客园)

  RMI的介绍不多说,因为我也不是非常理解,不敢妄加说明,还怕误导别人。

  我的集群环境是两台硬件服务器分别为A服务器和B服务器,每台服务器上有两个tomcat,A服务器上的是Tomcat1和Tomcat2,B服务器上的是Tomcat3和Tomcat4,大家一定要注意环境,因为有的环境不同,配置就不同,RMI集群有两种方式配置:自动成员发现和手动成员发现。我采用的是自动成员发现(本人不会考虑手动成员发现,局限性太大,不利于项目的统一部署,原因是:因为每次都要修改配置文件)。项目是通过Spring配置文件来加载ehcache.xml的,不再说明,这里只说ehcache.xml配置(配置中的中文注释是在编写这篇文章的时候添加的,因为这个配置文件中存在中文注释让我的项目启动不起来):

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"  
monitoring="autodetect">
<diskStore path="java.io.tmpdir" /> <!--缓存成员发现工厂,管理cacheManager对象 -->
<cacheManagerPeerProviderFactory  
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"  
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446,
        multicastPacketTimeToLive=32" /> <!--针对cacheManager事件的监听,这里只介绍properties中的hostName、port属性,
这里我忽略了hostName的配置,查看他们的源码发现如果不填写hostName,
他们就会通过JDK中的InterAddress.getLocalHost().getHostAddress()获取本机的ip地址,
所以在这里我没有填写hostName的配置,方便部署到多台硬件服务器上。
但是如果一台已经服务器上有多个网卡,这里一定要指定hostName的IP,原因参考InterAddress源码。
post这里我指定的时40001,如果这里不填写port配置,ehcache就会通过ServerSocket的getLocalPort获取一个本机没有被占用的端口 -->
<cacheManagerPeerListenerFactory  
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"  
properties="port=40001" /> <!--默认缓存配置 -->
<defaultCache maxElementsInMemory="10000" eternal="false"  
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="false"  
maxElementsOnDisk="10000000" diskPersistent="false"  
diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> <!--自定义缓存配置1 -->
<cache name="cache1" maxElementsInMemory="10000"  
maxElementsOnDisk="10000" eternal="false" overflowToDisk="false"  
diskSpoolBufferSizeMB="20" timeToIdleSeconds="7200" timeToLiveSeconds="7200"  
diskPersistent="false" memoryStoreEvictionPolicy="LFU"> <!--监听缓存事件,缓存移除、修改的时候同步其他服务器(Tomcat)的缓存,时间限制,具体属性不在这里说明 -->
<cacheEventListenerFactory  
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"  
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy=false, replicateRemovals=true " />
<!--服务器(Tomcat)启动就同步其他服务器(Tomcat)中的缓存,时间限制,具体属性不再这里说明 -->
<bootstrapCacheLoaderFactory  
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
</cache> <!--自定义缓存配置2 -->
<cache name="cache2" maxElementsInMemory="10000"  
maxElementsOnDisk="10000" eternal="false" overflowToDisk="false"  
diskSpoolBufferSizeMB="20" timeToIdleSeconds="7200" timeToLiveSeconds="7200"  
diskPersistent="false" memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory  
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"  
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy=false, replicateRemovals=true " />
<bootstrapCacheLoaderFactory  
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
</cache>
</ehcache>

最新文章

  1. 纯脚本组装Json格式字符串
  2. Routine Problem(数学)
  3. 1500: [NOI2005]维修数列
  4. 减小Delphi的Exe文件大小(11种方法)
  5. POJ2718 递归套递归
  6. 一、源代码-面向CLR的编译器-托管模块-(元数据&amp;IL代码)
  7. PhoneGap开发环境搭建
  8. ReSharper 全教程
  9. Android基础知识点-Manifest清单文件
  10. jQuery的ajax使用
  11. Bootstrap模态框钩子事件
  12. docker简单介绍----镜像和容器管理
  13. Python爬虫与一汽项目【三】爬取中国五矿集团采购平台
  14. ggplot的boxplot添加显著性 | Add P-values and Significance Levels to ggplots | 方差分析
  15. MySQL InnoDB 逻辑存储结构
  16. Git基础(三) 跟踪文件
  17. .Net core的日志系统
  18. PHP多进程编程之僵尸进程问题
  19. BZOJ2744:[HEOI2012]朋友圈(最大团,乱搞)
  20. 使用Fortify进行代码静态分析(系列文章)

热门文章

  1. zap安装和部署
  2. web服务器、wsgi、应用
  3. 使用JProfiler分析定位java内存泄露memory leak
  4. postman(一)批量执行接口测试用例
  5. linux系统预留内存和磁盘大小
  6. RabbitMQ二----&#39; helllo world &#39;
  7. JavaScript类数组转换为数组 面试题
  8. Android开发环境搭建 for windows (linux类似) 详细可参考“文件”中“Android开发环境搭建.pdf ”
  9. .net core 2.0小白笔记(一):开发运行环境搭建
  10. HTMLTestRunner 异常输出中文乱码