当前位置: 首页 > news >正文

做公众号模板的网站网站开发制作培训学校

做公众号模板的网站,网站开发制作培训学校,h5网站怎么做api对接,现在公司一般用什么邮箱本文使用rmi方式,借鉴百度能搜到的文章&#xff0c;但是均不能做到数据同步&#xff0c;做了些改动完全没问题&#xff0c;更详细说明介绍百度即可。直奔主题&#xff0c;可运行的demo实例&#xff01; 创建一个maven项目&#xff0c;配置pom pom.xml <dependencies><…

本文使用rmi方式,借鉴百度能搜到的文章,但是均不能做到数据同步,做了些改动完全没问题,更详细说明介绍百度即可。直奔主题,可运行的demo实例!

创建一个maven项目,配置pom

pom.xml

<dependencies><dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache</artifactId><version>2.10.0</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>4.1.6.RELEASE</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.5.8</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.5.8</version></dependency><dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache-jgroupsreplication</artifactId><version>1.7</version></dependency></dependencies>

服务器A 配置

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"><diskStore path="java.io.tmpdir/ehcache" /><!-- 指定除自身之外的网络群体中其他提供同步的主机列表,多台机器配置 用'|'分割 --><cacheManagerPeerProviderFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"properties="peerDiscovery=manual,rmiUrls=//192.168.1.74:4005/demoCache"></cacheManagerPeerProviderFactory><cacheManagerPeerListenerFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"properties="hostName=192.168.1.23,port=4005,socketTimeoutMillis=120000" /> <!-- 多播方式配置搜索某个网段上的缓存 timeToLive 0是限制在同一个服务器 1是限制在同一个子网 32是限制在同一个网站 64是限制在同一个region 128是限制在同一个大洲 255是不限制 <cacheManagerPeerProviderFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"properties="peerDiscovery=automatic, multicastGroupAddress=224.1.1.1,multicastGroupPort=40000, timeToLive=32" /> --><!-- 默认缓存 --><defaultCache maxElementsInMemory="1000" eternal="true"timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"diskPersistent="true" diskExpiryThreadIntervalSeconds="120"memoryStoreEvictionPolicy="LRU"></defaultCache><!-- demo缓存 --><cache name="demoCache" maxElementsInMemory="1000" eternal="false"timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"diskPersistent="false" diskExpiryThreadIntervalSeconds="120"memoryStoreEvictionPolicy="LRU"><cacheEventListenerFactoryclass="net.sf.ehcache.distribution.RMICacheReplicatorFactory" /><!-- 用于在初始化缓存,以及自动设置 --><bootstrapCacheLoaderFactoryclass="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /></cache>
</ehcache>

测试代码。

Mytest.java

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;public class Mytest {public static void main(String[] args) throws InterruptedException {CacheManager manager = new CacheManager("src/test/resources/ehcache.xml");   //get Cache        Cache cache = manager.getCache("demoCache");     Thread.sleep(10000); Element element = new Element("key","test");  cache.put(element);  System.out.println("Initial:\n"//+url.toString() +"\n"+manager.getName() +"\n"+cache.getName() +" 's size = "+cache.getSize() +"\n"+element.toString());     Element element01 = cache.get("key");        System.out.println(element01.getValue());  System.out.println("主机测试等待中.............");  while(true){ Thread.sleep(1000); } } 
}

服务器B

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"><diskStore path="java.io.tmpdir/ehcache" /><cacheManagerPeerProviderFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"properties="peerDiscovery=manual,rmiUrls=//192.168.1.23:4005/demoCache"></cacheManagerPeerProviderFactory><cacheManagerPeerListenerFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"properties="hostName=192.168.1.74,port=4005,socketTimeoutMillis=120000" /> <!-- 多播方式配置搜索某个网段上的缓存 timeToLive 0是限制在同一个服务器 1是限制在同一个子网 32是限制在同一个网站 64是限制在同一个region 128是限制在同一个大洲 255是不限制 <cacheManagerPeerProviderFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"properties="peerDiscovery=automatic, multicastGroupAddress=224.1.1.1,multicastGroupPort=40000, timeToLive=32" /> --><!-- 默认缓存 --><defaultCache maxElementsInMemory="1000" eternal="true"timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"diskPersistent="true" diskExpiryThreadIntervalSeconds="120"memoryStoreEvictionPolicy="LRU"></defaultCache><!-- demo缓存 --><cache name="demoCache" maxElementsInMemory="1000" eternal="false"timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"diskPersistent="false" diskExpiryThreadIntervalSeconds="120"memoryStoreEvictionPolicy="LRU"><cacheEventListenerFactoryclass="net.sf.ehcache.distribution.RMICacheReplicatorFactory" /><!-- 用于在初始化缓存,以及自动设置 --><bootstrapCacheLoaderFactoryclass="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /></cache>
</ehcache>

测试代码

MyTest.java

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;public class Mytest {public static void main(String[] args) throws InterruptedException {CacheManager manager = new CacheManager("src/test/resources/ehcache.xml");   //get Cache        Cache cache = manager.getCache("demoCache");     Thread.sleep(10000); while(true){ System.out.println("搜索中...");  System.out.println("当前资源数:" + cache.getSize());  Element element = cache.get("key");  if (element != null) {  System.out.println(element.getValue());   break;  } Thread.sleep(1000); } } 
}

 先运行服务器A,在运行服务器B。

效果:

服务器A

服务器B

 

完成!

转载于:https://www.cnblogs.com/mangyang/p/5481713.html

http://www.lbrq.cn/news/2394469.html

相关文章:

  • 用蜗牛做logo的网站武汉seo首页优化公司
  • 模板网站的弊端在哪品牌推广方案包括哪些
  • 用vs2005做网站 怎样搭配色彩百度灰色关键词排名代做
  • 苏州模板建站哪家好爱站网排名
  • 网站推广和网站优化seo怎么读
  • wordpress 导出功能seo怎么发外链的
  • 学校网站怎么下载不了打广告去哪个平台免费
  • 深圳网站制作工具怎么快速优化关键词
  • 有什么做视频的免费素材网站搜索排名优化软件
  • 有机大米网站建设方案怎么做谷歌推广
  • 企业网站建设应该怎么做宁波正规优化seo价格
  • 公司建设网站费用会计怎么记网络口碑营销的成功案例
  • seo网站推广作用活动营销推广方案
  • 5G网站建设要多少个四川seo优化
  • 搭配服装网站源码英雄联盟韩国
  • 武汉地区网站建设seo赚钱培训
  • 什么是微网站企业管理培训课程网课免费
  • 皮具网站建设网络营销策划书封面
  • 珠海专业网站制作公司搜索引擎优化工作
  • 注册科技有限公司经营范围百度seo发帖推广
  • 山东seo广西seo搜索引擎优化
  • 西安知名网站建设公司线上网络平台推广
  • 青岛网站建设 上流刚刚发生了一件大事
  • 青岛私人做网站网上企业推广
  • 保定网站建设优化西安seo霸屏
  • ppt做会动彩字网站手机网站建设案例
  • 网站推广文案怎么写医院网络销售要做什么
  • 有什么做照片书的网站百度seo排名优化软件
  • 西藏自治区住房建设厅网站软件定制
  • 旅游网络推广怎么做seo手机优化软件哪个好用
  • 论文略读: RASA: RANK-SHARING LOW-RANK ADAPTATION
  • 【音视频协议篇】RTSP系列
  • 大模型军备竞赛升级!Grok 4 携 “多智能体内生化” 破局,重构 AI 算力与 Agent 2.0 时代
  • Temperature 是在LLM中的每一层发挥作用,还是最后一层? LLM中的 Temperature 参数 是怎么计算的
  • 异步解决一切问题 |消息队列 |减少嵌套 |hadoop |rabbitmq |postsql
  • 尚庭公寓-----day2 业务功能实现