一、版本相关

   ehcache-jgroupsreplication-1.7.jar

   jgroups-3.4.1.Final.jar

   ehcache-core-2.6.5.jar

   hibernate3.6.10.Final.jar


二、EhCache ehcache.xml配置

<?xmlversion="1.0"encoding="UTF-8"?>
<ehcachexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"updateCheck="true"
monitoring="autodetect"dynamicConfig="true">
<diskStorepath="E:/WS/temp/ehcahe"/>
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="connect=UDP(mcast_addr=230.0.0.1;mcast_port=45566;tos=32;mcast_recv_buf_size=120000;mcast_send_buf_size=80000;
loopback=true;discard_incompatible_packets=true;max_bundle_size=64K;max_bundle_timeout=30;
ip_ttl=32;enable_bundling=true;enable_diagnostics=true;thread_naming_pattern=cl;
timer_type=new;timer.min_threads=4;timer.max_threads=10;timer.keep_alive_time=3000;timer.queue_max_size=500;
thread_pool.enabled=true;thread_pool.min_threads=2;thread_pool.max_threads=8;thread_pool.keep_alive_time=5000;
thread_pool.queue_enabled=true;thread_pool.queue_max_size=10000;thread_pool.rejection_policy=discard;oob_thread_pool.enabled=true;
oob_thread_pool.min_threads=1;oob_thread_pool.max_threads=8;oob_thread_pool.keep_alive_time=5000;
oob_thread_pool.queue_enabled=false;oob_thread_pool.queue_max_size=100;oob_thread_pool.rejection_policy=Run):
PING(timeout=2000;num_initial_members=6):
MERGE2(min_interval=5000;max_interval=10000):
VERIFY_SUSPECT(timeout=1500):
pbcast.NAKACK(use_mcast_xmit=true;discard_delivered_msgs=true;retransmit_timeout=1200):
UNICAST(timeout=1200):
pbcast.STABLE(desired_avg_gossip=20000;stability_delay=1000;max_bytes=4M):
pbcast.GMS(print_local_addr=true;join_timeout=3000;view_bundling=true):
FRAG2(frag_size=60K)"
propertySeparator="::"/>
<defaultCachemaxEntriesLocalHeap="10000"eternal="false"
timeToIdleSeconds="600"timeToLiveSeconds="600"overflowToDisk="true"
diskPersistent="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true,replicateUpdatesViaCopy=true,
replicateRemovals=true,asynchronousReplicationIntervalMillis=200" />
<bootstrapCacheLoaderFactoryclass="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true,maximumChunkSizeBytes=50000000"/>
</defaultCache>
<cachename="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"eternal="false"timeToIdleSeconds="600"
timeToLiveSeconds="600"overflowToDisk="true">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true,replicateUpdatesViaCopy=true,
replicateRemovals=true,asynchronousReplicationIntervalMillis=200" />
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=50000000"/>
</cache>
<cachename="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000"eternal="false"timeToIdleSeconds="600"
timeToLiveSeconds="600"overflowToDisk="true">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true,replicateUpdatesViaCopy=true,
replicateRemovals=true,asynchronousReplicationIntervalMillis=200" />
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=50000000"/>
</cache>
</ehcache>


三、Hibernate applicationContext.xml配置

<context:component-scanbase-package="com.clusterehcache"/>
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<propertyname="dataSource">
<refbean="dataSource"/>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.format_sql">true</prop>
<propkey="hibernate.cache.use_second_level_cache">true</prop>
<propkey="hibernate.cache.use_query_cache">true</prop>
<propkey="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</prop>
</props>
</property>
<propertyname="packagesToScan">
<list>
<value>com.clusterehcache.centity</value>
</list>
</property>
</bean>

四、Entity配置

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) 
publicclassUser {
……
}