2

我尝试使用 ehcache 并且它有效。我只是想用 ehcache RMI 实现分布式缓存。我按照网址中提供的步骤操作:http ://ehcache.org/documentation/distributed_caching_with_rmi.html?cf03800515=21D4D871!NTAxODEzNDE0OmNvcnByYWRpdXNzc286vsRypkVtSPb7t3MnL22gFQ==#

但我找不到分布式缓存工作......

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//<remotemachineip>:<i want to know what port id should be given here>/deviceCache1"/>

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=<localmachineip>,port=<i want to know what port id should be given here>,
socketTimeoutMillis=120000"/>

我给了一些端口号,我在两台机器上都有独立的 java 代码。首先,我在朋友的机器上运行主程序,将数据放入“deviceCache1”,然后我尝试在我的主程序中访问该缓存。但我没有发现两台机器之间发生任何连接。

我可能听起来很傻,但我需要知道一些关于缓存的事情。请有人澄清我的疑问并帮助我。所以,我的问题是: 1. 需要在两台机器的 ehcache.xml 中提供哪些端口 ID?2. 我是否需要启用一些 Windows 服务才能使用 rmi 端口?3.我需要添加任何其他代码来连接两台机器吗?

请尽快帮助我。谢谢

4

2 回答 2

3

由于评论大小限制,这将回答您的问题

服务器 1 上的配置将是这样的

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
    properties="hostName=localhost, port=40001,socketTimeoutMillis=2000"/>

server2 上的配置将是这样的

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
    properties="hostName=localhost, port=40002,socketTimeoutMillis=2000"/>

如果您仍然遇到问题,请粘贴您的 ehcache.xml。如果它回答了您的问题,请接受答案。

于 2011-02-04T17:49:40.250 回答
0

您还需要将 cacheEventListenerFactory 添加到缓存中(需要复制)

memoryStoreEvictionPolicy="LFU" diskPersistent="true"
timeToLiveSeconds="86400" maxElementsOnDisk="1000">

您可以提供任何端口(系统未使用的端口)

于 2011-02-03T23:50:27.567 回答