recluster_ehcache_0.xml
properties="peerDiscovery=manual,rmiUrls=//10.1.36.100:40000/UserCache"/>
properties="hostName=10.1.36.100,port=40001,socketTimeoutMillis=120000" />
diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
overflowToDisk="false">
recluster_ehcache.xml
properties="peerDiscovery=manual,rmiUrls=//127.0.0.1:40001/UserCache"/>
properties="hostName=10.1.36.100,port=40000,socketTimeoutMillis=120000" />
diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
overflowToDisk="false">
代码:
package cache.echache.Init;
import java.net.URL;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class clustertest {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException{
// TODO Auto-generated method stub
//URL url = clustertest.class.getClassLoader().getResource("recluster_ehcache.xml");
CacheManager manager = new CacheManager("recluster_ehcache.xml");
//get Cache
Cache cache = manager.getCache("UserCache");
Thread.sleep(10000);
Element element = new Element("key1", "value1");
Element element1 = new Element("key12", "value1");
Element element2 = new Element("key13", "value1");
Element element3 = new Element("key14", "value1");
cache.put(element);
cache.put(element1);
cache.put(element2);
cache.put(element3);
System.out.println("Initial:\n"//+url.toString()
+"\n"+manager.getName()
+"\n"+cache.getName()
+" 's size = "+cache.getSize()
+"\n"+element.toString());
Element element01 = cache.get("key1");
System.out.println(element01.getValue());
Element element02 = cache.get("key12");
System.out.println(element02.getValue());
System.out.println("主机测试等待中.............");
while(true){
Thread.sleep(1000);
}
}
}
package cache.echache.Init;
import java.net.URL;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class clustertest0 {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException{
// TODO Auto-generated method stub
//URL url = clustertest.class.getClassLoader().getResource("recluster_ehcache.xml");
CacheManager manager = new CacheManager("recluster_ehcache_0.xml");
//get Cache
Cache cache = manager.getCache("UserCache");
Thread.sleep(10000);
/*Element element = new Element("key1", "value1");
Element element1 = new Element("key12", "value1");
Element element2 = new Element("key13", "value1");
Element element3 = new Element("key14", "value1");
cache.put(element);
cache.put(element1);
cache.put(element2);
cache.put(element3);
System.out.println("Initial:\n"//+url.toString()
+"\n"+manager.getName()
+"\n"+cache.getName()
+" 's size = "+cache.getSize()
+"\n"+element.toString()); */
/*Element element01 = cache.get("key1");
System.out.println(element01.getValue());
System.out.println("主机测试等待中............."); */
while(true){
Element element01 = cache.get("key1");
if(null!=element01){
System.out.println(element01.getValue());
}
Thread.sleep(1000);
}
}
}