解惑

解己之惑,解人之惑

使用JBossCache作为Hibernate的二级缓存

这个是最近的工作成果,使用JBossCache作为Hibernate的二级缓存,因为JBossCache支持Transactional的缓存策略(Strategy),而且支持Cluster,Cluster还支持Invalidation的方式,比Replication方式更好,对两种方式同时支持同步和异步,还有其他很多特性,比OSCache好得多。
由于我们是把Hibernate作为服务配置的,所以CacheProviderClass使用的是org.jboss.hibernate.cache.DeployedTreeCacheProvider,需要另外一个MBean进行TreeCache的配置:
<mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=HibernateTreeCache">
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
<attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
<attribute name="EvictionPolicyConfig">
            <config>
                <attribute name="wakeUpIntervalSeconds">10</attribute>
                <region name="/_default_" policyClass="org.jboss.cache.eviction.LRUPolicy">
                    <attribute name="maxNodes">5000</attribute>
                    <attribute name="timeToIdleSeconds">300</attribute>
                </region>
            </config>
</attribute>
<attribute name="IsolationLevel">REPEATABLE_READ</attribute>
<attribute name="CacheMode">INVALIDATION_ASYNC</attribute>
<attribute name="ClusterName">HibernateInvalidatedReplicatedCache</attribute>
<attribute name="LockAcquisitionTimeout">15000</attribute>
    <attribute name="ClusterConfig">
      <config>
        <UDP mcast_addr="101.101.101.101"
             mcast_port="55588"
             ucast_recv_buf_size="20000000"
             ucast_send_buf_size="640000"
             mcast_recv_buf_size="25000000"
             mcast_send_buf_size="640000"
             loopback="false"
             max_bundle_size="64000"
             max_bundle_timeout="30"
             use_incoming_packet_handler="true"
             use_outgoing_packet_handler="true"
             ip_ttl="${jgroups.mcast.ip_ttl:2}"
             down_thread="false" up_thread="false"
             enable_bundling="true"/>
        <PING timeout="2000"
              down_thread="false" up_thread="false" num_initial_members="3"/>
        <MERGE2 max_interval="100000"
                down_thread="false" up_thread="false" min_interval="20000"/>
        <FD_SOCK down_thread="false" up_thread="false"/>
        <FD shun="true" up_thread="false" down_thread="false"
            timeout="20000" max_tries="5"/>
        <VERIFY_SUSPECT timeout="1500"
                        up_thread="false" down_thread="false"/>
        <pbcast.NAKACK max_xmit_size="60000"
                       use_mcast_xmit="false" gc_lag="50"
                       retransmit_timeout="300,600,1200,2400,4800"
                       down_thread="false" up_thread="false"
                       discard_delivered_msgs="true"/>
        <UNICAST timeout="300,600,1200,2400,3600"
                 down_thread="false" up_thread="false"/>
        <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
                       down_thread="false" up_thread="false"
                       max_bytes="400000"/>
        <pbcast.GMS print_local_addr="true" join_timeout="3000"
                    down_thread="false" up_thread="false"
                    join_retry_timeout="2000" shun="true"/>
        <FC max_credits="2000000" down_thread="false" up_thread="false"
            min_threshold="0.10"/>
        <FRAG2 frag_size="60000" down_thread="false" up_thread="false"/>
        <pbcast.STATE_TRANSFER down_thread="false" up_thread="false"/>
      </config>
    </attribute>
</mbean>

2007年8月1日更新:
不能使用乐观锁,因为要使用乐观锁必须使用特定的那个Provider Class:OptimisticTreeCacheProvider,其他的信息可以自己看看Jboss的Wiki文档

(Visited 800 times, 1 visits today)

5 Comments

  1. javaresearch怎么了
    ?关闭了吗?

  2. 服务器坏了
    我们在重新买机器和选择机房,应该这个周末可以弄好

  3. :em02: Hibernate好学么?感觉技术的东西学着很累,JAVA出的技术太多了,要不断的学习。

  4. Hibernate入门比较简单,但是深入可能也不是简单的事情 :em32:

  5. 引用:
    [Cherami

    2007-07-25
    Hibernate入门比较简单,但是深入可能也不是简单的事情]

    说的有道理,hibernate是个上手快,进步难的东西,学习中。只有克服瓶颈才能获得真正的知识。

发表评论

邮箱地址不会被公开。 必填项已用*标注

© 2024 解惑

本主题由Anders Noren提供向上 ↑