⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch07s16.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
executes inside or outside a transaction.</p><p>
Option B: The container caches the bean between transactions.
However, unlike option A the container does not have exclusive
access to the persistent storage. Therefore, the container will
synchronize the memory state (via ejbLoad) at the beginning of
each transaction. Thus business methods executing in a transaction
context don't see much benefit from the container caching the bean,
whereas business methods executing outside a transaction context
(transaction attributes Never, NotSupported or Supports) access
the cached (and invalid) state of the bean.</p><p>
Option C: The container does not cache bean instances and instances
memory state is synchronized on every transaction start (via ejbLoad).
For business methods executing outside a transaction the synchronization
is done too, but as the ejbLoad executes in the same transaction context
as the triggering business method, the state must still be considered
invalid and might already have changed in the persistent storage when
the business method executes.</p><p>
Option D: This is a JBoss specific feature available from version 2.4. It enables a lazy read schema, where
the beans state is cached between transactions as with option A,
but resynchronized from the persistent storage from time to time
(via ejbLoad). The default time between resynchronizations is 30
seconds but you may configure the time (in seconds) with
&lt;optiond-refresh-rate&gt;42&lt;/optiond-refresh-rate&gt;.</p><p>
With all four commit options the container must synchronize the
bean instances cached state with the persistent storage (via ejbStore)
at the end of each transaction (just before a commit is done)
to be sure the whole transactions state is consistently persistet.
As of the EJB specification there is no safe way for the container to
decide, if the beans state actually has changed since transaction
start, so ejbStore is called, even when all access to the beans
business methods was read only. Note, however, that JBoss supports
an optional method public boolean isModified() in the beans
implementation. If this method returns false, the call to ejbStore
is skipped at commit time.</p><p>
A final note to executing business methods outside of a transaction
context: when reading the beans state you always must consider
the result as invalid and usable for rough display purposes only,
i.e. to fill in a large table, having benefit from bean caching (with
options A, B and D) and avoiding unneccessary concurrency; even with
commit option A, though you get the actual state initially, another
concurrent client might change the beans state a microsecond after
your read. Never write access a bean outside a transaction context
believing ejbStore will be called for synchronization, it typically
will not (though somtimes it might, when the container passivates
the bean) be called. Read the EJB specification 1.1 sections 9.1.7.1
and 11.6.3 carefully, if you plan to use the transaction attributes
Never, NotSupported or Supports.</p><p>
To safely write a bean depending on it's current state ever (re)read
and write the bean within one and the same transaction context.
</p></li></ul></div></div><div class="section"><a name="adv.config-cache"></a><div class="titlepage"><div><h3 class="title"><a name="adv.config-cache"></a>Advanced cache configuration</h3></div></div><p>JBoss currently provides the possibility to choose the cache configuration for 
each container configuration. You may want 
to define your own cache settings, and to do so you must specify them in 
jboss.xml under the &lt;instance-cache&gt; tag and 
subtags. Currently 2 cache algorithms have been implemented: a no passivation 
cache algorithm (so that all the bean are
kept in memory, unless the bean is an entity bean and you specified for it 
commit option C), and a least recently used (LRU)
cache algorithm (so that bean less frequently used are passivated to save 
server resources).
</p><p>Let's see how to configure both caches. The examples below are about entity 
beans, but the cache settings applies as well
for stateful session beans.For the no passivation cache, jboss.xml will look 
like this:</p><pre class="programlisting">
&lt;jboss&gt;                                                               
  &lt;enterprise-beans&gt;
    &lt;entity&gt;
      &lt;ejb-name&gt;Bean A&lt;/ejb-name&gt;
      &lt;configuration-name&gt;No Passivation Configuration&lt;configuration-name&gt;
    &lt;/entity&gt;
  &lt;enterprise-beans&gt;
  ...
  &lt;container-configurations&gt;
    &lt;container-configuration&gt;
      &lt;container-name&gt;No Passivation Configuration&lt;/container-name&gt;
      ...
      &lt;instance-cache&gt;org.jboss.ejb.plugins.EntitySessionInstanceCache&lt;/instance-cache&gt;
      &lt;container-cache-conf&gt;
        &lt;cache-policy&gt;org.jboss.ejb.plugins.NoPassivationCachePolicy&lt;/cache-policy&gt;
      &lt;/container-cache-conf&gt;
      ...
    &lt;/container-configuration&gt;
  &lt;/container-configurations&gt;
  ...
&lt;/jboss&gt;                                                               
</pre><p>No further settings are available for the no passivation cache.
For the LRU cache, jboss.xml will look like this:</p><pre class="programlisting">
&lt;jboss&gt;                                                               
  &lt;enterprise-beans&gt;
    &lt;entity&gt;
      &lt;ejb-name&gt;Bean A&lt;/ejb-name&gt;
      &lt;configuration-name&gt;LRU Configuration&lt;configuration-name&gt;
    &lt;/entity&gt;
  &lt;enterprise-beans&gt;
  ...
  &lt;container-configurations&gt;
    &lt;container-configuration&gt;
      &lt;container-name&gt;LRU Configuration&lt;/container-name&gt;
      ...
      &lt;instance-cache&gt;org.jboss.ejb.plugins.EntitySessionInstanceCache&lt;/instance-cache&gt;
      &lt;container-cache-conf&gt;
        &lt;cache-policy&gt;org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy&lt;/cache-policy&gt; 
     
        &lt;cache-policy-conf&gt;
          &lt;min-capacity&gt;5&lt;/min-capacity&gt;
          &lt;max-capacity&gt;200&lt;/max-capacity&gt;
          &lt;overager-period&gt;300&lt;/overager-period&gt;
          &lt;max-bean-age&gt;600&lt;/max-bean-age&gt;
          &lt;resizer-period&gt;400&lt;/resizer-period&gt;
          &lt;max-cache-miss-period&gt;60&lt;/max-cache-miss-period&gt;
          &lt;min-cache-miss-period&gt;1&lt;/min-cache-miss-period&gt;
          &lt;cache-load-factor&gt;0.75&lt;/cache-load-factor&gt;
        &lt;/cache-policy-conf&gt;
      &lt;/container-cache-conf&gt;
      ...
    &lt;/container-configuration&gt;
  &lt;/container-configurations&gt;
  ...
&lt;/jboss&gt; 
</pre><div class="itemizedlist"><ul><li><p><a name="d0e2842"></a>&lt;cache-policy-conf&gt; and its subtags are optional, so you 
can specify none, few or all of them.
&lt;min-capacity&gt; specifies the minimum capacity of the cache. The 
cache can be empty, but will have room for at least
5 beans (in the above case); this value cannot be less than 2; the resizer 
(see below) will shrink the cache capacity 
down to but not less than this value.
</p></li><li><p><a name="d0e2845"></a>&lt;max-capacity&gt; specifies the maximum capacity of the 
cache. The cache can be empty, but will have room for at most 200
beans (in the above case); this value cannot be less than the minimum 
capacity; the resizer (see below) will enlarge the
cache capacity up to but not more than this value.
</p></li><li><p><a name="d0e2848"></a>&lt;overager-period&gt; specifies the period of the overager, 
that is a periodic task that runs (in the above case) every 300
seconds. Purpose of this periodic task is to see if in the cache there are 
very old beans, and to passivate them. 
The age at which a bean is considered too old is also configurable (see 
below). While the period of this task is 300 seconds, the first run happens at 
a random time between 0 and 300 seconds.
</p></li><li><p><a name="d0e2851"></a>&lt;max-bean-age&gt; specifies the max age a bean can have 
before being passivated by the overager (in this case 600 seconds).
The tag &lt;resizer-period&gt; specifies the period of the resizer, that 
is a periodic task that runs (in the above case) every 
400 seconds. Purpose of this periodic task is to shrink / enlarge the cache 
capacity upon 3 other parameters (see below).
While the period of this task is 400 seconds, the first run happens at a 
random time between 0 and 400 seconds. 
</p></li><li><p><a name="d0e2854"></a>&lt;max-cache-miss-period&gt;,&lt;min-cache-miss-period&gt; 
and &lt;cache-load-factor&gt; control the resizer in this way: the 
number of 
cache misses is internally recorded. When the resizer runs, it sees what is 
the cache miss rate from the last time it ran.
If there is more than (in the above case) one cache miss every 1 second 
(min-cache-miss-period) then the resizer tries to 
enlarge the cache; if there is less than (in this case) one cache miss every 
60 seconds (max-cache-miss-period) then the 
resizer tries to shrink the cache. How much is the cache enlarged / shrinked ? 
Here is where the load-factor comes in the
picture. When the resizer shrinks, it tries to shrink the cache so that (in 
this case) the ratio number of beans / cache 
capacity is 0.75; when the resizer enlarges, it tries to enlarge the cache by 
a factor 1 / 0.75 == 1.333 (in the above case) plus a correction calculated 
from the cache miss rate (so that the more cache miss rate you have, the more 
the cache is enlarged, starting from at least 1.333; so if you really have a 
lot of cache misses, the resizer may decide to enlarge the cache of a factor 
2.0 instead of 1.333 - if there is room for that).
</p></li></ul></div></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch07s13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07s13.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch07s22.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07s22.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -