简体   繁体   English

使用单个配置在同一台计算机上运行ehcache的多个实例

[英]running multiple instances of ehcache on the same machine with a single config

im trying to set up a replicated ehcache that can run both over a local network and on the same machine. 我试图建立一个可以同时在本地网络和同一台计算机上运行的复制ehcache。 my current config looks like this: 我当前的配置如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<diskStore path="java.io.tmpdir"/>

<!-- clustering -->
<cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, multicastPacketTimeToLive=255"
        propertySeparator=","/>

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

<cache name="demo-cache"
       maxEntriesLocalHeap="0"
       maxEntriesLocalDisk="0"
       eternal="true"
       overflowToDisk="true"
       maxBytesLocalHeap="10M"
       diskPersistent="false"
       diskSpoolBufferSizeMB="5"
       clearOnFlush="false">
    <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true "/>
</cache>

this works across different machines, but does not work with multiple instances on the same machine. 这适用于不同的计算机,但不适用于同一计算机上的多个实例。 i know that playing around with the peer listener factory port (40001, 40002 etc) will probbaly work, but im hoping that there's a configuration that will "just work" in both scenarios. 我知道使用对等侦听器工厂端口(40001、40002等)可能会起作用,但我希望有一种配置在两种情况下都“可以正常使用”。

I know this is old topic but I also had similar problem. 我知道这是旧话题,但我也遇到类似问题。 In such case I used configuration like below: 在这种情况下,我使用如下配置:

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"     properties="" />

Try with hostname=localhost y port=0 in cacheManagerPeerListenerFactory. 尝试在cacheManagerPeerListenerFactory中使用hostname = localhost y port = 0。 It should work. 它应该工作。

If you set up 0 for port, RMICacheManagerPeerListenerFactory will allocate differents random ports intead of the same. 如果将端口设置为0,则RMICacheManagerPeerListenerFactory将为相同的端口分配不同的随机端口。

short answer is i cant. 简短的回答是我不能。 the jgroups support in ehcache 2.5 doesnt work and with RMI each node needs its own port. ehcache 2.5中的jgroups支持不起作用,并且对于RMI,每个节点都需要自己的端口。

what i eventually did was create the conf from the xml, parse the port out of the properties field for the peer listener factory and run a loop that creates ServerSockets until it finds a free port (meaning the ServerSocket constructor doesnt throw an exception) and uses that. 我最终要做的是从xml创建conf,从属性字段中解析出对等侦听器工厂的端口,并运行创建ServerSockets的循环,直到找到可用端口(这意味着ServerSocket构造函数不会抛出异常)并使用那。 its ugly but it works 它很丑但是可以用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当同一应用程序的两个实例正在运行时,EHCache挂起 - EHCache hangs when two instances of same app is running 在一台W7机器上运行Java应用程序(Salesforce DataLoader)的多个实例? - Running multiple instances of a Java app (Salesforce DataLoader) on a single W7 machine? 在一台Windows机器上运行多个Tomcat实例 - Running Multiple Tomcat Instances on One Windows Machine 如何在单台机器上运行同一窗口服务(java)的多个实例 - How can I run multiple instances of the same window service(java) in single machine 在同一台机器上设置多个JBoss实例 - Setting up multiple instances of JBoss on the same machine ehcache不在同一台机器上的两个tomcat之间复制 - Ehcache not replicating between two tomcat on the same machine 单个MySQL实例+ Hibernate Config与多个MySQL实例 - Single MySQL instance + Hibernate Config vs Multiple MySQL instances 在同一台计算机上为不同的应用程序运行多个jvm - Running multiple jvms for different applications in same machine 在同一台机器上运行的多个Java程序 - Multiple Java programs running on the same machine Java相同类的多个实例共享相同的运行对象,但是它们不应该 - Java multiple instances of same class share the same running objects, but they shoud not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM