??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品午夜视频,亚洲视频精选在线,福利h视频在线http://www.aygfsteel.com/paulwong/category/50662.htmlzh-cnSat, 24 Aug 2019 00:16:02 GMTSat, 24 Aug 2019 00:16:02 GMT60SPRING CACHE之ConcurrentMapCacheManager攚w?/title><link>http://www.aygfsteel.com/paulwong/archive/2015/02/25/423034.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 25 Feb 2015 08:34:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2015/02/25/423034.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/423034.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2015/02/25/423034.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/423034.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/423034.html</trackback:ping><description><![CDATA[ConcurrentMapCacheManager可以作ؓ一U缓存方案,但不能设|过期,最大缓存条目等Q需q行攚w?br /> <ol> <li>pom.xml中加入依赖包<br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->        <span style="color: #0000FF; "><</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span>com.google.guava<span style="color: #0000FF; "></</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span>guava<span style="color: #0000FF; "></</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span><br />            <span style="color: #0000FF; "><</span><span style="color: #800000; ">version</span><span style="color: #0000FF; ">></span>18.0<span style="color: #0000FF; "></</span><span style="color: #800000; ">version</span><span style="color: #0000FF; ">></span><br />        <span style="color: #0000FF; "></</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span></div> <br /> </li> <li>攚wCacheManagerQMyConcurrentMapCacheManager<br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">package</span> com.paul.common.cache;<br /><span style="color: #008000; ">/*</span><span style="color: #008000; "><br /> * Copyright 2002-2014 the original author or authors.<br /> *<br /> * Licensed under the Apache License, Version 2.0 (the "License");<br /> * you may not use this file except in compliance with the License.<br /> * You may obtain a copy of the License at<br /> *<br /> *      </span><span style="color: #008000; text-decoration: underline; ">http://www.apache.org/licenses/LICENSE-2.0</span><span style="color: #008000; "><br /> *<br /> * Unless required by applicable law or agreed to in writing, software<br /> * distributed under the License is distributed on an "AS IS" BASIS,<br /> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br /> * See the License for the specific language governing permissions and<br /> * limitations under the License.<br /> </span><span style="color: #008000; ">*/</span><br /><br /><span style="color: #0000FF; ">import</span> java.util.Collection;<br /><span style="color: #0000FF; ">import</span> java.util.Collections;<br /><span style="color: #0000FF; ">import</span> java.util.Map;<br /><span style="color: #0000FF; ">import</span> java.util.concurrent.ConcurrentHashMap;<br /><span style="color: #0000FF; ">import</span> java.util.concurrent.ConcurrentMap;<br /><span style="color: #0000FF; ">import</span> java.util.concurrent.TimeUnit;<br /><br /><span style="color: #0000FF; ">import</span> org.springframework.cache.Cache;<br /><span style="color: #0000FF; ">import</span> org.springframework.cache.CacheManager;<br /><span style="color: #0000FF; ">import</span> org.springframework.cache.concurrent.ConcurrentMapCache;<br /><br /><span style="color: #0000FF; ">import</span> com.google.common.cache.CacheBuilder;<br /><br /><span style="color: #008000; ">/**</span><span style="color: #008000; "><br /> * {</span><span style="color: #808080; ">@link</span><span style="color: #008000; "> CacheManager} implementation that lazily builds {</span><span style="color: #808080; ">@link</span><span style="color: #008000; "> ConcurrentMapCache}<br /> * instances for each {</span><span style="color: #808080; ">@link</span><span style="color: #008000; "> #getCache} request. Also supports a 'static' mode where<br /> * the set of cache names is pre-defined through {</span><span style="color: #808080; ">@link</span><span style="color: #008000; "> #setCacheNames}, with no<br /> * dynamic creation of further cache regions at runtime.<br /> *<br /> * <p>Note: This is by no means a sophisticated CacheManager; it comes with no<br /> * cache configuration options. However, it may be useful for testing or simple<br /> * caching scenarios. For advanced local caching needs, consider<br /> * {</span><span style="color: #808080; ">@link</span><span style="color: #008000; "> org.springframework.cache.guava.GuavaCacheManager} or<br /> * {</span><span style="color: #808080; ">@link</span><span style="color: #008000; "> org.springframework.cache.ehcache.EhCacheCacheManager}.<br /> *<br /> * </span><span style="color: #808080; ">@author</span><span style="color: #008000; "> Juergen Hoeller<br /> * </span><span style="color: #808080; ">@since</span><span style="color: #008000; "> 3.1<br /> * </span><span style="color: #808080; ">@see</span><span style="color: #008000; "> ConcurrentMapCache<br /> </span><span style="color: #008000; ">*/</span><br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> MyConcurrentMapCacheManager <span style="color: #0000FF; ">implements</span> CacheManager {<br /><br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">final</span> ConcurrentMap<String, Cache> cacheMap = <span style="color: #0000FF; ">new</span> ConcurrentHashMap<String, Cache>(16);<br /><br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">boolean</span> dynamic = <span style="color: #0000FF; ">true</span>;<br /><br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">boolean</span> allowNullValues = <span style="color: #0000FF; ">true</span>;<br />    <br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">long</span> expireTime = 30;<br />    <br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">long</span> maximumSize = 100;<br /><br /><br />    <span style="color: #008000; ">/**</span><span style="color: #008000; "><br />     * Construct a dynamic ConcurrentMapCacheManager,<br />     * lazily creating cache instances as they are being requested.<br />     </span><span style="color: #008000; ">*/</span><br />    <span style="color: #0000FF; ">public</span> MyConcurrentMapCacheManager() {<br />    }<br /><br />    <span style="color: #008000; ">/**</span><span style="color: #008000; "><br />     * Construct a static ConcurrentMapCacheManager,<br />     * managing caches for the specified cache names only.<br />     </span><span style="color: #008000; ">*/</span><br />    <span style="color: #0000FF; ">public</span> MyConcurrentMapCacheManager(<span style="color: #0000FF; ">long</span> expireTime, <span style="color: #0000FF; ">long</span> maximumSize) {<br />        <span style="color: #0000FF; ">if</span>(expireTime > 0)<br />            <span style="color: #0000FF; ">this</span>.expireTime = expireTime;<br />        <span style="color: #0000FF; ">if</span>(maximumSize > 0)<br />            <span style="color: #0000FF; ">this</span>.maximumSize = maximumSize;<br />    }<br /><br /><br />    <span style="color: #008000; ">/**</span><span style="color: #008000; "><br />     * Specify the set of cache names for this CacheManager's 'static' mode.<br />     * <p>The number of caches and their names will be fixed after a call to this method,<br />     * with no creation of further cache regions at runtime.<br />     * <p>Calling this with a {</span><span style="color: #808080; ">@code</span><span style="color: #008000; "> null} collection argument resets the<br />     * mode to 'dynamic', allowing for further creation of caches again.<br />     </span><span style="color: #008000; ">*/</span><br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> setCacheNames(Collection<String> cacheNames) {<br />        <span style="color: #0000FF; ">if</span> (cacheNames != <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">for</span> (String name : cacheNames) {<br />                <span style="color: #0000FF; ">this</span>.cacheMap.put(name, createConcurrentMapCache(name));<br />            }<br />            <span style="color: #0000FF; ">this</span>.dynamic = <span style="color: #0000FF; ">false</span>;<br />        }<br />        <span style="color: #0000FF; ">else</span> {<br />            <span style="color: #0000FF; ">this</span>.dynamic = <span style="color: #0000FF; ">true</span>;<br />        }<br />    }<br /><br />    <span style="color: #008000; ">/**</span><span style="color: #008000; "><br />     * Specify whether to accept and convert {</span><span style="color: #808080; ">@code</span><span style="color: #008000; "> null} values for all caches<br />     * in this cache manager.<br />     * <p>Default is "true", despite ConcurrentHashMap itself not supporting {</span><span style="color: #808080; ">@code</span><span style="color: #008000; "> null}<br />     * values. An internal holder object will be used to store user-level {</span><span style="color: #808080; ">@code</span><span style="color: #008000; "> null}s.<br />     * <p>Note: A change of the null-value setting will reset all existing caches,<br />     * if any, to reconfigure them with the new null-value requirement.<br />     </span><span style="color: #008000; ">*/</span><br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> setAllowNullValues(<span style="color: #0000FF; ">boolean</span> allowNullValues) {<br />        <span style="color: #0000FF; ">if</span> (allowNullValues != <span style="color: #0000FF; ">this</span>.allowNullValues) {<br />            <span style="color: #0000FF; ">this</span>.allowNullValues = allowNullValues;<br />            <span style="color: #008000; ">//</span><span style="color: #008000; "> Need to recreate all Cache instances with the new null-value configuration<img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span style="color: #008000; "><br /></span>            <span style="color: #0000FF; ">for</span> (Map.Entry<String, Cache> entry : <span style="color: #0000FF; ">this</span>.cacheMap.entrySet()) {<br />                entry.setValue(createConcurrentMapCache(entry.getKey()));<br />            }<br />        }<br />    }<br /><br />    <span style="color: #008000; ">/**</span><span style="color: #008000; "><br />     * Return whether this cache manager accepts and converts {</span><span style="color: #808080; ">@code</span><span style="color: #008000; "> null} values<br />     * for all of its caches.<br />     </span><span style="color: #008000; ">*/</span><br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">boolean</span> isAllowNullValues() {<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">this</span>.allowNullValues;<br />    }<br /><br /><br />    @Override<br />    <span style="color: #0000FF; ">public</span> Collection<String> getCacheNames() {<br />        <span style="color: #0000FF; ">return</span> Collections.unmodifiableSet(<span style="color: #0000FF; ">this</span>.cacheMap.keySet());<br />    }<br /><br />    @Override<br />    <span style="color: #0000FF; ">public</span> Cache getCache(String name) {<br />        Cache cache = <span style="color: #0000FF; ">this</span>.cacheMap.get(name);<br />        <span style="color: #0000FF; ">if</span> (cache == <span style="color: #0000FF; ">null</span> && <span style="color: #0000FF; ">this</span>.dynamic) {<br />            <span style="color: #0000FF; ">synchronized</span> (<span style="color: #0000FF; ">this</span>.cacheMap) {<br />                cache = <span style="color: #0000FF; ">this</span>.cacheMap.get(name);<br />                <span style="color: #0000FF; ">if</span> (cache == <span style="color: #0000FF; ">null</span>) {<br />                    cache = createConcurrentMapCache(name);<br />                    <span style="color: #0000FF; ">this</span>.cacheMap.put(name, cache);<br />                }<br />            }<br />        }<br />        <span style="color: #0000FF; ">return</span> cache;<br />    }<br /><br />    <span style="color: #008000; ">/**</span><span style="color: #008000; "><br />     * Create a new ConcurrentMapCache instance for the specified cache name.<br />     * </span><span style="color: #808080; ">@param</span><span style="color: #008000; "> name the name of the cache<br />     * </span><span style="color: #808080; ">@return</span><span style="color: #008000; "> the ConcurrentMapCache (or a decorator thereof)<br />     </span><span style="color: #008000; ">*/</span><br />    <span style="color: #0000FF; ">protected</span> Cache createConcurrentMapCache(String name) {<br /><span style="color: #008000; ">        //</span><span style="color: #008000; ">return new ConcurrentMapCache(name, isAllowNullValues());<br /></span><span style="color: #008000; ">        //</span><span style="color: #008000; ">此处改用GOOGLE GUAVA的构造MANAGER方式</span><span style="color: #008000; "><br /></span>        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> ConcurrentMapCache(name,<br />                                        CacheBuilder.newBuilder()<br />                                                    .expireAfterWrite(<span style="color: #0000FF; ">this</span>.expireTime, TimeUnit.MINUTES)<br />                                                    .maximumSize(<span style="color: #0000FF; ">this</span>.maximumSize)<br />                                                    .build()<br />                                                    .asMap(), <br />                                        isAllowNullValues());<br />    }<br /><br />}</div><br /> <br /> </li> <li>配置想着bean, cache-concurrentmap-applicationcontext.xml<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; "><?</span><span style="color: #FF00FF; ">xml version="1.0" encoding="UTF-8"</span><span style="color: #0000FF; ">?></span><br /><span style="color: #0000FF; "><</span><span style="color: #800000; ">beans </span><span style="color: #FF0000; ">xmlns</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/beans"</span><span style="color: #FF0000; "><br />    xmlns:xsi</span><span style="color: #0000FF; ">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: #FF0000; "> xmlns:context</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/context"</span><span style="color: #FF0000; "><br />    xmlns:cache</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/cache"</span><span style="color: #FF0000; "><br />    xmlns:p</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/p"</span><span style="color: #FF0000; "><br />    xmlns:c</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/c"</span><span style="color: #FF0000; "><br />    xmlns:jee</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/jee"</span><span style="color: #FF0000; "><br />    xmlns:util</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/util"</span><span style="color: #FF0000; "><br />    xsi:schemaLocation</span><span style="color: #0000FF; ">="http://www.springframework.org/schema/context<br />          http://www.springframework.org/schema/context/spring-context-3.0.xsd<br />          http://www.springframework.org/schema/beans<br />          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<br />          http://www.springframework.org/schema/cache<br />          http://www.springframework.org/schema/cache/spring-cache.xsd<br />          http://www.springframework.org/schema/jee <br />          http://www.springframework.org/schema/jee/spring-jee.xsd<br />          http://www.springframework.org/schema/util<br />          http://www.springframework.org/schema/util/spring-util.xsd"</span><span style="color: #0000FF; ">></span><br /><br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">cache:annotation-driven </span><span style="color: #0000FF; ">/></span><br /><br />    <span style="color: #008000; "><!--</span><span style="color: #008000; "> <bean id="cacheManager"<br />        class="org.springframework.cache.concurrent.ConcurrentMapCacheManager" ><br />        <property name="cacheNames"><br />            <list><br />                <value>my-local-cache</value><br />            </list><br />        </property><br />    </bean> </span><span style="color: #008000; ">--></span><br />    <br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">bean </span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="cacheManager"</span><span style="color: #FF0000; "><br />        class</span><span style="color: #0000FF; ">="com.paul.common.cache.MyConcurrentMapCacheManager"</span><span style="color: #0000FF; ">></span><br />        <span style="color: #0000FF; "><</span><span style="color: #800000; ">constructor-arg </span><span style="color: #FF0000; ">index</span><span style="color: #0000FF; ">="0"</span><span style="color: #FF0000; "> value</span><span style="color: #0000FF; ">="1"</span><span style="color: #FF0000; "> </span><span style="color: #0000FF; ">/></span><br />        <span style="color: #0000FF; "><</span><span style="color: #800000; ">constructor-arg </span><span style="color: #FF0000; ">index</span><span style="color: #0000FF; ">="1"</span><span style="color: #FF0000; "> value</span><span style="color: #0000FF; ">="5000"</span><span style="color: #FF0000; "> </span><span style="color: #0000FF; ">/></span><br />    <span style="color: #0000FF; "></</span><span style="color: #800000; ">bean</span><span style="color: #0000FF; ">></span>    <br />    <br /><span style="color: #0000FF; "></</span><span style="color: #800000; ">beans</span><span style="color: #0000FF; ">></span></div> <br /> <br /> </li> <li>通过注释q行使用<br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">/*</span><span style="color: #008000; "><br /> * JBoss, Home of Professional Open Source<br /> * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual<br /> * contributors by the @authors tag. See the copyright.txt in the<br /> * distribution for a full listing of individual contributors.<br /> *<br /> * Licensed under the Apache License, Version 2.0 (the "License");<br /> * you may not use this file except in compliance with the License.<br /> * You may obtain a copy of the License at<br /> * </span><span style="color: #008000; text-decoration: underline; ">http://www.apache.org/licenses/LICENSE-2.0</span><span style="color: #008000; "><br /> * Unless required by applicable law or agreed to in writing, software<br /> * distributed under the License is distributed on an "AS IS" BASIS,<br /> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br /> * See the License for the specific language governing permissions and<br /> * limitations under the License.<br /> </span><span style="color: #008000; ">*/</span><br /><span style="color: #0000FF; ">package</span> com.paul.springmvc.data;<br /><br /><span style="color: #0000FF; ">import</span> java.util.List;<br /><br /><span style="color: #0000FF; ">import</span> javax.persistence.EntityManager;<br /><span style="color: #0000FF; ">import</span> javax.persistence.criteria.CriteriaBuilder;<br /><span style="color: #0000FF; ">import</span> javax.persistence.criteria.CriteriaQuery;<br /><span style="color: #0000FF; ">import</span> javax.persistence.criteria.Root;<br /><br /><span style="color: #0000FF; ">import</span> org.springframework.beans.factory.annotation.Autowired;<br /><span style="color: #0000FF; ">import</span> org.springframework.cache.annotation.CacheEvict;<br /><span style="color: #0000FF; ">import</span> org.springframework.cache.annotation.Cacheable;<br /><span style="color: #0000FF; ">import</span> org.springframework.stereotype.Repository;<br /><span style="color: #0000FF; ">import</span> org.springframework.transaction.annotation.Transactional;<br /><br /><span style="color: #0000FF; ">import</span> com.paul.springmvc.model.Member;<br /><br />@Repository<br />@Transactional<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> MemberDaoImpl <span style="color: #0000FF; ">implements</span> MemberDao {<br />    @Autowired<br />    <span style="color: #0000FF; ">private</span> EntityManager em;<br /><br />    @Cacheable(value = "my-local-cache", key = "#id")<br />    <span style="color: #0000FF; ">public</span> Member findById(Long id) {<br />        System.out.println("<img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" />MemberDaoImpl NO CACHE<img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" />");<br />        <span style="color: #0000FF; ">return</span> em.find(Member.<span style="color: #0000FF; ">class</span>, id);<br />    }<br /><br />    <span style="color: #0000FF; ">public</span> Member findByEmail(String email) {<br />        CriteriaBuilder cb = em.getCriteriaBuilder();<br />        CriteriaQuery<Member> criteria = cb.createQuery(Member.<span style="color: #0000FF; ">class</span>);<br />        Root<Member> member = criteria.from(Member.<span style="color: #0000FF; ">class</span>);<br /><br />        <span style="color: #008000; ">/*</span><span style="color: #008000; "><br />         * Swap criteria statements if you would like to try out type-safe criteria queries, a new<br />         * feature in JPA 2.0 criteria.select(member).orderBy(cb.asc(member.get(Member_.name)));<br />         </span><span style="color: #008000; ">*/</span><br /><br />        criteria.select(member).where(cb.equal(member.get("email"), email));<br />        <span style="color: #0000FF; ">return</span> em.createQuery(criteria).getSingleResult();<br />    }<br /><br />    <span style="color: #0000FF; ">public</span> List<Member> findAllOrderedByName() {<br />        CriteriaBuilder cb = em.getCriteriaBuilder();<br />        CriteriaQuery<Member> criteria = cb.createQuery(Member.<span style="color: #0000FF; ">class</span>);<br />        Root<Member> member = criteria.from(Member.<span style="color: #0000FF; ">class</span>);<br /><br />        <span style="color: #008000; ">/*</span><span style="color: #008000; "><br />         * Swap criteria statements if you would like to try out type-safe criteria queries, a new<br />         * feature in JPA 2.0 criteria.select(member).orderBy(cb.asc(member.get(Member_.name)));<br />         </span><span style="color: #008000; ">*/</span><br /><br />        criteria.select(member).orderBy(cb.asc(member.get("name")));<br />        <span style="color: #0000FF; ">return</span> em.createQuery(criteria).getResultList();<br />    }<br /><br />    @CacheEvict(value="my-local-cache",allEntries=<span style="color: #0000FF; ">true</span>,beforeInvocation=<span style="color: #0000FF; ">true</span>)<span style="color: #008000; ">//</span><span style="color: #008000; ">清空所有缓?/span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> register(Member member) {<br />        em.persist(member);<br />        <span style="color: #0000FF; ">return</span>;<br />    }<br />}</div></li> </ol><img src ="http://www.aygfsteel.com/paulwong/aggbug/423034.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2015-02-25 16:34 <a href="http://www.aygfsteel.com/paulwong/archive/2015/02/25/423034.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SPRING CACHE资源http://www.aygfsteel.com/paulwong/archive/2015/02/25/423032.htmlpaulwongpaulwongWed, 25 Feb 2015 08:04:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/02/25/423032.htmlhttp://www.aygfsteel.com/paulwong/comments/423032.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/02/25/423032.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/423032.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/423032.html
http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/htmlsingle/#cache

SPRING CONCURRENTMAP MANAGER加过期策?br />http://stackoverflow.com/questions/8181768/can-i-set-a-ttl-for-cacheable

l合KEY
http://stackoverflow.com/questions/14072380/cacheable-key-on-multiple-method-arguments

Spring Cache抽象详解
http://www.open-open.com/lib/view/open1389575623336.html

注释驱动?Spring cache ~存介绍
https://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/

Spring Cache抽象详解



paulwong 2015-02-25 16:04 发表评论
]]>
使用WILDFLY中的分布式缓存INFISHPANhttp://www.aygfsteel.com/paulwong/archive/2015/02/23/422998.htmlpaulwongpaulwongMon, 23 Feb 2015 05:40:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/02/23/422998.htmlhttp://www.aygfsteel.com/paulwong/comments/422998.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/02/23/422998.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/422998.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/422998.html
  • 通过http://127.0.0.1:9991/console/App.html#infinispandCACHE
    <cache-container name="tickets" default-cache="default" jndi-name="java:jboss/infinispan/tickets">
           <local-cache name="default" batching="true">
                  <locking isolation="REPEATABLE_READ"/>
           </local-cache>
    </cache-container>

  • pom.xmld依赖?br />
            <dependency>
                <groupId>org.infinispan</groupId>
                <artifactId>infinispan-core</artifactId>
                <scope>provided</scope>
            </dependency>
            
            <dependency>
                <groupId>org.infinispan</groupId>
                <artifactId>infinispan-client-hotrod</artifactId>
                <scope>provided</scope>
            </dependency>

        <dependency>
            <groupId>org.jgroups</groupId>
            <artifactId>jgroups</artifactId>
            <scope>provided</scope>
        </dependency>

            <dependency>
                <groupId>org.infinispan</groupId>
                <artifactId>infinispan-spring</artifactId>
                <version>6.0.2.Final</version>
            </dependency>
            
            <dependency>
                <groupId>org.infinispan</groupId>
                <artifactId>infinispan-jcache</artifactId>
                <version>6.0.2.Final</version>
            </dependency>

  • d拦截器,WEB-INF/beans.xml
    <?xml version="1.0"?>
    <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
        <interceptors>
            <class>org.infinispan.jcache.annotation.CacheResultInterceptor</class>
            <class>org.infinispan.jcache.annotation.CachePutInterceptor</class>
            <class>org.infinispan.jcache.annotation.CacheRemoveEntryInterceptor</class>
            <class>org.infinispan.jcache.annotation.CacheRemoveAllInterceptor</class>
        </interceptors>
    </beans>

  • d目的全局依赖QWEB-INF/jboss-deployment-structure.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.jboss.xnio" />
                <module name="org.infinispan" export="true"/>
                <module name="org.infinispan.commons" export="true"/>
                <module name="org.infinispan.client.hotrod" export="true"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>

  • 在CDI BEAN中用CACHE
    package com.paul.myejb;

    import javax.annotation.Resource;
    import javax.cache.annotation.CacheResult;
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    import javax.interceptor.Interceptors;

    import org.infinispan.Cache;
    import org.infinispan.manager.EmbeddedCacheManager;
    //import org.springframework.cache.annotation.Cacheable;
    import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

    /**
     * Session Bean implementation class HelloWorldBean
     
    */
    @Stateless
    //@Local(HelloWorld.class)
    @Remote(HelloWorld.class)
    @Interceptors(SpringBeanAutowiringInterceptor.class)
    //@RolesAllowed({Roles.ADMIN})
    public class HelloWorldBean implements HelloWorld {
        
        @Resource(lookup = "java:jboss/infinispan/tickets")
        private EmbeddedCacheManager container;
        
        
        /**
         * Default constructor. 
         
    */
        public HelloWorldBean() {
        }

    //    @Transactional
    //    @Cacheable(value = "books", key = "#name")
        @CacheResult
        public String sayHello(String name) {
            System.out.println("NO CACHE");
            String result = "Hello " + name + ", I am HelloWorldBean.";
            Cache<String, String> cache = this.container.getCache();
            cache.put(name, result);
            return result;
        }

    }


  • 修改modules/system/layers/base/org/infinispan/client/hotrod/main/modules.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
      ~ JBoss, Home of Professional Open Source.
      ~ Copyright 2010, Red Hat, Inc., and individual contributors
      ~ as indicated by the @author tags. See the copyright.txt file in the
      ~ distribution for a full listing of individual contributors.
      ~
      ~ This is free software; you can redistribute it and/or modify it
      ~ under the terms of the GNU Lesser General Public License as
      ~ published by the Free Software Foundation; either version 2.1 of
      ~ the License, or (at your option) any later version.
      ~
      ~ This software is distributed in the hope that it will be useful,
      ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
      ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      ~ Lesser General Public License for more details.
      ~
      ~ You should have received a copy of the GNU Lesser General Public
      ~ License along with this software; if not, write to the Free
      ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
      ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
      
    -->
    <module xmlns="urn:jboss:module:1.3" name="org.infinispan.client.hotrod">
        <properties>
            <property name="jboss.api" value="private"/>
        </properties>

        <resources>
            <resource-root path="infinispan-client-hotrod-6.0.2.Final.jar"/>
        </resources>

        <dependencies>
            <module name="javax.api"/>
            <!--下面q一行注释掉-->
            <!--<module name="com.google.protobuf"/>-->
            <module name="org.apache.commons.pool"/>
            <module name="org.infinispan.commons"/>
            <module name="org.infinispan.query.dsl"/>
            <module name="org.jboss.logging"/>
        </dependencies>
    </module>

  • 以下是SPRING版本
    1. d依赖的SPRING BEAN
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi
      ="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
          xmlns:cache
      ="http://www.springframework.org/schema/cache"
          xmlns:p
      ="http://www.springframework.org/schema/p"
          xmlns:jee
      ="http://www.springframework.org/schema/jee"
          xsi:schemaLocation
      ="http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/cache
                http://www.springframework.org/schema/cache/spring-cache.xsd
                http://www.springframework.org/schema/jee 
                http://www.springframework.org/schema/jee/spring-jee.xsd"
      >

          <cache:annotation-driven />
          
          <bean id="cacheManager"
                class
      ="org.infinispan.spring.provider.ContainerCacheManagerFactoryBean">
                <constructor-arg ref="cacheContainer"  />
          </bean>
          
          <jee:jndi-lookup id="cacheContainer" jndi-name="java:jboss/infinispan/tickets" > 
          </jee:jndi-lookup>
          
          <!-- <bean id="cacheContainer"
                class="com.paul.myejb.common.util.cache.JndiSpringCacheManagerFactoryBean"
                p:infinispanJNDI="java:jboss/infinispan/tickets" /> 
      -->
          
      </beans>

    2. 使用CACHE
      package com.paul.myejb.spring;

      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.cache.CacheManager;
      import org.springframework.cache.annotation.Cacheable;
      import org.springframework.stereotype.Component;

      @Component
      public class MySpringBean {
          
          @Autowired
          private CacheManager cacheManager;
          
          @Cacheable(value = "my-local-cache", key = "#name")
          public String sayHello(String name)
          {
              System.out.println("MySpringBean NO CACHE");
              String result = "Hi " + name + ", I am Spring!";
              org.springframework.cache.Cache springCache = this.cacheManager.getCache("my-local-cache");
              System.out.println(springCache.get(name) == null ? "null" : springCache.get(name).get());
              springCache.put(name, result);
              return result;
          }

      }




    paulwong 2015-02-23 13:40 发表评论
    ]]>
    Infinispan资源http://www.aygfsteel.com/paulwong/archive/2015/02/22/422993.htmlpaulwongpaulwongSun, 22 Feb 2015 06:03:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/02/22/422993.htmlhttp://www.aygfsteel.com/paulwong/comments/422993.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/02/22/422993.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/422993.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/422993.html 使用时最好与SPRINGl合Q用在DAO层?br /> 以某Ҏ参数作ؓKEYQ返回的对象作ؓVALUE保存到缓存中?br /> ADD/EDIT/REMOVEҎ被执行时则清除所有的~存?br />
    Infinispan的运行模式有两种Q?br /> 1、嵌入式
    先启动一个进E,再在此进E中启动Infinispan的CACHE MANAGER?br /> 2、CLIENT/SERVER
    直接q行startserver.sh来启动?br />
    两者区?br /> 嵌入式:
    1、Infinispan和启动进E是在同一个进E里Q如JBOSS中的Infinispan
    2、要使用Infinispan的CACHEQ必d应用部v到此q程中,如将WAR应用部v到JBOSS?br /> 3、如有多台机以此模式q行Q则互相可以通讯

    CLIENT/SERVERQ?br /> 1、Infinispan单独一个进E?br /> 2、通过SDKQ以MEMCHAEDQRHQ{协议访问CACHE
    3、如有多台机以此模式q行Q互怸可以通讯

    JBOSS中的INFINISPAN肯定是嵌入式Q要讉KINFINISPAN的CACHE必须部v到JBOSS才能讉KQ没有远E模式?/span>

    Infinispan中的CACHE有两U模式:本地~存和集缓存?br />
    本地~存是单机版?br /> 集群~存是多机网l版Q又分ؓ三种Q?br /> 1、分布式Q网l中的每个节点只保存部䆾~存条目Q所有的节点合v来保存全部缓存条?br /> 当本机无此条目时Q要通过|络d别的机器上取
    2、复制式Q网l中的每个节炚w保存全部~存条目Q但~存条目有更新时Q所有节点一q更?br /> 当本机无此条目时Q不用到别的节点取,但缓存条目有更新Ӟ所有节炚w会执行更新本地缓存操?br /> 3、无效式Q网l中的每个节点互不通讯Q但~存条目有更新时Q节Ҏ到失效通知Q各自处理本机的~存条目

    ~程使用Ҏ
    1、通过E序使用Q即在代码中写cache的存取?br /> 2、通过注释使用Q这各注释是通过截面拦截Ҏ方式实现Q即如果在缓存中有此~存条目Q则Ҏ不会被执行,直接q回l果?br /> 又细分两U:
    通过SPRING实现Q通过JAVA EE的CDI实现?br />
    JBoss pd三十一QJBoss Data GridQInfinispanQ缓存模?/a>

    JBoss pd三十二:JBoss Data GridQInfinispanQ缓存模式示?/a>


    infinispan-quickstart


    https://docs.jboss.org/infinispan/5.0/apidocs/org/infinispan/spring/provider/package-summary.html


    Infinispan integrate with spring based application
    http://timtang.me/blog/2012/11/04/infinispan-spring-based-application-integration/


    Java~存新标准(javax.cacheQ?br /> http://www.importnew.com/11723.html

    https://developer.jboss.org/en/infinispan/cn/content?filterID=contentstatus[published]~objecttype~objecttype[document]

    paulwong 2015-02-22 14:03 发表评论
    ]]>
    几大NOSQL数据库性能比较http://www.aygfsteel.com/paulwong/archive/2015/01/30/422565.htmlpaulwongpaulwongThu, 29 Jan 2015 16:16:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/01/30/422565.htmlhttp://www.aygfsteel.com/paulwong/comments/422565.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/01/30/422565.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/422565.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/422565.htmlhttp://planetcassandra.org/nosql-performance-benchmarks

    NoSQL Benchmarking
    http://www.cubrid.org/blog/dev-platform/nosql-benchmarking/


    http://www.badrit.com/blog/2013/11/18/redis-vs-mongodb-performance#.VMpfW2SUfsg

    How many requests per second can I get out of Redis?
    http://skipperkongen.dk/2013/08/27/how-many-requests-per-second-can-i-get-out-of-redis/

    redis性能试Q测试ƈ发性能
    http://my.oschina.net/pblack/blog/102394

    paulwong 2015-01-30 00:16 发表评论
    ]]>
    腾讯CKV量分布式存储系l?/title><link>http://www.aygfsteel.com/paulwong/archive/2014/07/16/415866.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 15 Jul 2014 23:58:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2014/07/16/415866.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/415866.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2014/07/16/415866.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/415866.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/415866.html</trackback:ping><description><![CDATA[<img src="http://ww4.sinaimg.cn/bmiddle/a1ab8e59jw1eeeg66h72fj20c83ek7ra.jpg" width="440" height="4412" alt="" /><img src ="http://www.aygfsteel.com/paulwong/aggbug/415866.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2014-07-16 07:58 <a href="http://www.aygfsteel.com/paulwong/archive/2014/07/16/415866.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一些数据切分、缓存、rpc框架、nosqlҎ资料http://www.aygfsteel.com/paulwong/archive/2013/10/14/404954.htmlpaulwongpaulwongMon, 14 Oct 2013 02:14:00 GMThttp://www.aygfsteel.com/paulwong/archive/2013/10/14/404954.htmlhttp://www.aygfsteel.com/paulwong/comments/404954.htmlhttp://www.aygfsteel.com/paulwong/archive/2013/10/14/404954.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/404954.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/404954.html1、数据切?/span>

            1.1?a style="color: #108ac6;" target="_blank">mysql中间件研IӞAtlasQcobarQTDDLQ?/a> 

            1.2?a style="color: #108ac6;" target="_blank">利用 MySQL Proxy 实现数据切分及整?nbsp;

            1.3?a style="color: #108ac6;" target="_blank">ZMySQL分库分表Ҏ?nbsp;

            1.4?a style="color: #108ac6;" target="_blank">tddl和diamond  

    2、缓?/p>

            2.1?a style="color: #108ac6;" target="_blank">java客户端三U方式操?nbsp;

            2.2?a style="color: #108ac6;" target="_blank">myibatis配置memcached评测 

            2.3?a style="color: #108ac6;" target="_blank">Memcached + Spring Caching 

            2.4?a style="color: #108ac6;" target="_blank">memcachedb-持久化存储的~存pȝ 

            2.5?a style="color: #108ac6;" target="_blank">memcachedb让memcache的数据持久化 

            2.6?a style="color: #108ac6;" target="_blank">淘宝kv~存框架tair 

            2.7?a style="color: #108ac6;" target="_blank">ibatis之扩展缓存ibatis-tair-cache 

    3、rpc框架

            3.1?a style="color: #108ac6;">dubbo 

            3.2、hsf 未开?/p>

            3.3?a style="color: #108ac6;" target="_blank">服务框架HSF分析之一容器启动

    4、noSql

            4.1?a style="color: #108ac6;" target="_blank">学习NoSQL数据库的必读资料 



    paulwong 2013-10-14 10:14 发表评论
    ]]>
    单的开源分布式~存框架?/title><link>http://www.aygfsteel.com/paulwong/archive/2012/05/02/377145.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 02 May 2012 02:24:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2012/05/02/377145.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/377145.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2012/05/02/377145.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/377145.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/377145.html</trackback:ping><description><![CDATA[<div><a target="_blank" >http://code.google.com/p/xcache-j/</a></div><img src ="http://www.aygfsteel.com/paulwong/aggbug/377145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2012-05-02 10:24 <a href="http://www.aygfsteel.com/paulwong/archive/2012/05/02/377145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>实战Memcached~存pȝhttp://www.aygfsteel.com/paulwong/archive/2012/04/29/377039.htmlpaulwongpaulwongSun, 29 Apr 2012 13:42:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/04/29/377039.htmlhttp://www.aygfsteel.com/paulwong/comments/377039.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/04/29/377039.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/377039.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/377039.html
  • 实战Memcached~存pȝQ?QMemcached基础及示例程?/font>
  • 实战Memcached~存pȝQ?QMemcached Java API基础之MemcachedClient
    内容Q以Memcached的Java Spy APIZQ讲q基本的客户端用?
  • 实战Memcached~存pȝQ?QMemcached配置参数初解
    内容Q提供Memcached配置的初步解诅R?
  • 实战Memcached~存pȝQ?QMemcached的CAS协议
    内容QMemcached的CAS协议?
  • 实战Memcached~存pȝQ?QMemcached的CASE序实例
    内容QMemcached Client使用CAS协议的实例?
  • 实战Memcached~存pȝQ?QMemcached CAS的多U程E序实例
    内容QMemcached Client使用CAS协议的多U程实例?
  • 实战Memcached~存pȝQ?QMemcached的一些基FAQ
    内容Q一些关于Memcached的常见问题和基础知识汇总,不断更新中?
  • 实战Memcached~存pȝQ?QMemcached异步实时d问题的解x案SAC


  • paulwong 2012-04-29 21:42 发表评论
    ]]>
    SpringZ注解的缓存配|?-web应用实例http://www.aygfsteel.com/paulwong/archive/2012/02/16/370119.htmlpaulwongpaulwongThu, 16 Feb 2012 09:04:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/02/16/370119.htmlhttp://www.aygfsteel.com/paulwong/comments/370119.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/02/16/370119.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/370119.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/370119.html
    http://hanqunfeng.iteye.com/blog/605123

    l验证,如果要支持分布式的缓存,用spring-modules-cache不好使,必须转用com.googlecode.ehcache-spring-annotations?br />
    全套MAVEN的POM:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        
    <modelVersion>4.0.0</modelVersion>
        
    <groupId>EhCache-Cluster-Tester</groupId>
        
    <artifactId>EhCache-Cluster-Tester</artifactId>
        
    <version>0.0.1-SNAPSHOT</version>
        
    <packaging>war</packaging>
        
    <dependencies>
            
    <dependency>
                
    <groupId>net.sf.ehcache</groupId>
                
    <artifactId>ehcache-jgroupsreplication</artifactId>
                
    <version>1.4</version>
            
    </dependency>
            
    <!-- Spring framework -->
            
    <dependency>
                
    <groupId>org.springframework</groupId>
                
    <artifactId>spring</artifactId>
                
    <version>${spring.version}</version>
            
    </dependency>

            
    <!-- Spring MVC framework -->
            
    <dependency>
                
    <groupId>org.springframework</groupId>
                
    <artifactId>spring-webmvc</artifactId>
                
    <version>${spring.version}</version>
            
    </dependency>
            
    <dependency>
                
    <groupId>javax.servlet</groupId>
                
    <artifactId>servlet-api</artifactId>
                
    <version>2.4</version>
                
    <scope>provided</scope>
            
    </dependency>
            
    <dependency>
                
    <groupId>org.slf4j</groupId>
                
    <artifactId>slf4j-jdk14</artifactId>
                
    <version>1.5.6</version>
                
    <type>jar</type>
                
    <scope>compile</scope>
            
    </dependency>
            
    <dependency>
                
    <groupId>log4j</groupId>
                
    <artifactId>log4j</artifactId>
                
    <version>1.2.13</version>
                
    <type>jar</type>
                
    <scope>compile</scope>
            
    </dependency>
            
    <dependency>
                
    <groupId>cglib</groupId>
                
    <artifactId>cglib-nodep</artifactId>
                
    <version>2.2.2</version>
                
    <type>jar</type>
                
    <scope>compile</scope>
            
    </dependency>
            
    <!-- 
            <dependency>
                <groupId>org.springmodules</groupId>
                <artifactId>spring-modules-cache</artifactId>
                <version>0.9</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            
    -->
            
    <dependency>
                
    <groupId>com.googlecode.ehcache-spring-annotations</groupId>
                
    <artifactId>ehcache-spring-annotations</artifactId>
                
    <version>1.2.0</version>
                
    <type>jar</type>
                
    <scope>compile</scope>
                
    <exclusions>
                    
    <exclusion>
                        
    <artifactId>spring-aop</artifactId>
                        
    <groupId>org.springframework</groupId>
                    
    </exclusion>
                    
    <exclusion>
                        
    <artifactId>spring-expression</artifactId>
                        
    <groupId>org.springframework</groupId>
                    
    </exclusion>
                
    </exclusions>
            
    </dependency>
        
    </dependencies>
        
    <build>
            
    <finalName>cluster-test</finalName>
            
    <plugins>
                
    <plugin>
                    
    <groupId>org.apache.maven.plugins</groupId>
                    
    <artifactId>maven-compiler-plugin</artifactId>
                    
    <configuration>
                        
    <source>1.6</source>
                        
    <target>1.6</target>
                        
    <encoding>UTF-8</encoding>
                    
    </configuration>
                
    </plugin>
                
    <plugin>
                    
    <groupId>org.mortbay.jetty</groupId>
                    
    <artifactId>jetty-maven-plugin</artifactId>
                    
    <version>8.0.4.v20111024</version>
                    
    <!-- 
                    <artifactId>maven-jetty-plugin</artifactId>
                    <version>6.1.26</version>
                    
    -->
                    
    <configuration>
                        
    <contextPath>/cluster-test</contextPath>
                        
    <scanIntervalSeconds>3</scanIntervalSeconds>
                        
    <scanTargetPatterns>
                            
    <scanTargetPattern>
                                
    <directory>src/main/webapp/WEB-INF</directory>
                                
    <excludes>
                                    
    <exclude>**/*.jsp</exclude>
                                
    </excludes>
                                
    <includes>
                                    
    <include>**/*.properties</include>
                                    
    <include>**/*.xml</include>
                                
    </includes>
                            
    </scanTargetPattern>
                        
    </scanTargetPatterns>
                    
    </configuration>
                
    </plugin>
            
    </plugins>
        
    </build>
        
    <properties>
            
    <spring.version>2.5.2</spring.version>
        
    </properties>
    </project>


    paulwong 2012-02-16 17:04 发表评论
    ]]>
    Ehcache分布式缓?/title><link>http://www.aygfsteel.com/paulwong/archive/2012/02/14/369948.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 14 Feb 2012 07:46:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2012/02/14/369948.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/369948.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2012/02/14/369948.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/369948.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/369948.html</trackback:ping><description><![CDATA[?.2版本开始,Ehcache可以使用分布式的~存了?br /> <br /> 分布式这个特性是以plugin的方式实现的。Ehcache自带了一些默认的分布式缓存插件实玎ͼq些插g可以满大部分应用的需要。如果需要用其他的插g那就需要自己开发了Q开发者可以通过查看distribution包里的源代码及JavaDoc来实现它?br /> <br /> 管不是必须的,在用分布式~存时理解一些ehcahce的设计思想也是有帮助的。这可以参看分布式缓存设计的面?br /> 以下的部分将展示如何让分布式插g同ehcache一起工作?br /> <br /> 下面列出的是一些分布式~存中比较重要的斚wQ?br /> <br /> 你如何知道集环境中的其他缓存?分布式传送的消息是什么Ş式?什么情况需要进行复Ӟ增加QPutsQ,更新QUpdatesQ或是失效(ExpiriesQ?采用什么方式进行复Ӟ同步q是异步方式Q?br /> <br /> Z安装分布式缓存,你需要配|一个PeerProvider、一个CacheManagerPeerListenerQ它们对于一个CacheManager来说是全局的。每个进行分布式操作的cache都要d一个cacheEventListener来传送消息?br /> <br /> <strong>正确的元素类?/strong><br /> <br /> 只有可序列化的元素可以进行复制?br /> <br /> 一些操作,比如U除Q只需要元素的键D不用整个元素;在这L操作中即使元素不是可序列化的但键值是可序列化的也可以被复Ӟ<br /> <br /> <strong>成员发现QPeer DiscoveryQ?/strong><br /> <br /> Ehcacheq行集群的时候有一个cachel的概念。每个cache都是其他cache的一个peerQ没有主cache的存在。刚才我们问了一个问题:你如何知道集环境中的其他缓存?q个问题可以命名为成员发玎ͼPeer DiscoveryQ?br /> <br /> Ehcache提供了两U机制用来进行成员发玎ͼ像一辆汽车:手动档和自动档?br /> <br /> 要用一个内|的成员发现机制要在ehcache的配|文件中指定cacheManagerPeerProviderFactory元素的class属性ؓnet.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory?br /> <br /> <strong>自动的成员发?/strong><br /> <br /> 自动的发现方式用TCPq播机制来确定和l持一个广播组。它只需要一个简单的配置可以自动的在l中d和移除成员。在集群中也不需要什么优化服务器的知识,q是默认推荐的?br /> <br /> 成员每秒向群l发送一?#8220;心蟩”。如果一个成?5U种都没有发Z号它被组U除。如果一个新的成员发送了一?#8220;心蟩”它将被添加进组?br /> <br /> M一个用q个配置安装了复制功能的cache都将被其他的成员发现q标识ؓ可用状态?br /> <br /> 要设|自动的成员发现Q需要指定ehcache配置文g中cacheManagerPeerProviderFactory元素的properties属性,像下面q样Q?br /><br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">peerDiscovery=automatic multicastGroupAddress=multicast address | multicast host name multicastGroupPort=port <br /># (timeToLive属性详见常见问题部分的描述)<br />timeToLive=0-255</span></div><br /> CZ<br /> <br /> 假设你在集群中有两台服务器。你希望同步sampleCache1和sampleCache2。每台独立的服务器都要有q样的配|:<br /> 配置server1和server2<br /> <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; "><</span><span style="color: #800000; ">cacheManagerPeerProviderFactory<br /></span><span style="color: #FF0000; ">class</span><span style="color: #0000FF; ">="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"</span><span style="color: #FF0000; "><br />properties</span><span style="color: #0000FF; ">="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,<br />multicastGroupPort=4446, timeToLive=32"</span><span style="color: #0000FF; ">/></span></div><br /> <strong>手动q行成员发现</strong><br /> <br /> q行手动成员配置要知道每个监听器的IP地址和端口。成员不能在q行时动态地d和移除。在技术上很难使用q播的情况下可以手动成员发玎ͼ例如在集的服务器之间有一个不能传送广播报文的路由器。你也可以用手动成员发现q行单向的数据复Ӟ只让server2知道server1而server1不知道server2?br /> <br /> 配置手动成员发现Q需要指定ehcache配置文g中cacheManagerPeerProviderFactory的properties属性,像下面这P<br /> <br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">peerDiscovery</span><span style="color: #000000; ">=</span><span style="color: #000000; ">manual rmiUrls</span><span style="color: #000000; ">=</span><span style="color: #000000; ">//server:port/cacheName</span><span style="color: #000000; ">,</span><span style="color: #000000; "> <img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /><br />rmiUrls配置的是服务器cache peers的列表。注意不要重复配|?/span></div><br /> CZ<br /> <br /> 假设你在集群中有两台服务器。你要同步sampleCache1和sampleCache2。下面是每个服务器需要的配置Q?br /> 配置server1<br /> <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; "><</span><span style="color: #800000; ">cacheManagerPeerProviderFactory<br /></span><span style="color: #FF0000; ">class</span><span style="color: #0000FF; ">="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"</span><span style="color: #FF0000; "><br />properties</span><span style="color: #0000FF; ">="peerDiscovery=manual,<br />rmiUrls=//server2:40001/sampleCache11|//server2:40001/sampleCache12"</span><span style="color: #0000FF; ">/></span></div><br /> 配置server2<br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; "><</span><span style="color: #800000; ">cacheManagerPeerProviderFactory<br /></span><span style="color: #FF0000; ">class</span><span style="color: #0000FF; ">="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"</span><span style="color: #FF0000; "><br />properties</span><span style="color: #0000FF; ">="peerDiscovery=manual,<br />rmiUrls=//server1:40001/sampleCache11|//server1:40001/sampleCache12"</span><span style="color: #0000FF; ">/></span></div><br /> <strong>配置CacheManagerPeerListener</strong><br /> <br /> 每个CacheManagerPeerListener监听成员们发向当前CacheManager的消息?br /> 配置CacheManagerPeerListener需要指定一个CacheManagerPeerListenerFactoryQ它以插件的机制实现Q用来创建CacheManagerPeerListener?br /> <br /> cacheManagerPeerListenerFactory的属性有Q?br /> class – 一个完整的工厂cd?br /> properties – 只对q个工厂有意义的属性,使用逗吃分隔?br /> <br /> Ehcache有一个内|的ZRMI的分布系l。它的监听器是RMICacheManagerPeerListenerQ这个监听器可以用RMICacheManagerPeerListenerFactory来配|?br /> <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; "><</span><span style="color: #800000; ">cacheManagerPeerListenerFactory<br /></span><span style="color: #FF0000; ">class</span><span style="color: #0000FF; ">="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"</span><span style="color: #FF0000; "><br />properties</span><span style="color: #0000FF; ">="hostName=localhost, port=40001,<br />socketTimeoutMillis=2000"</span><span style="color: #0000FF; ">/></span></div><br />有效的属性是Q?br /> hostname (可? – q行监听器的服务器名U。标明了做ؓ集群组的成员的地址Q同时也是你惌控制的从集群中接收消息的接口?br /> <br /> 在CacheManager初始化的时候会查hostname是否可用?br /> <br /> 如果hostName不可用,CacheManager拒l启动ƈ抛出一个连接被拒绝的异常?br /> <br /> 如果指定Qhostname用InetAddress.getLocalHost().getHostAddress()来得到?br /> <br /> 警告Q不要将localhost配置为本地地址127.0.0.1Q因为它在网l中不可见将会导致不能从q程服务器接收信息从而不能复制。在同一台机器上有多个CacheManager的时候,你应该只用localhost来配|?br /> <br /> port – 监听器监听的端口?br /> socketTimeoutMillis (可? – Socket时的时间。默认是2000ms?br /> <br /> <strong>配置CacheReplicators</strong><br /> <br /> 每个要进行同步的cache都需要设|一个用来向CacheManagerr的成员复制消息的~存事g监听器。这个工作要通过为每个cache的配|增加一个cacheEventListenerFactory元素来完成?br /> <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; "><!--</span><span style="color: #008000; "> Sample cache named sampleCache2. </span><span style="color: #008000; ">--></span><span style="color: #000000; "><br /></span><span style="color: #0000FF; "><</span><span style="color: #800000; ">cache </span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="sampleCache2"</span><span style="color: #FF0000; "><br />maxElementsInMemory</span><span style="color: #0000FF; ">="10"</span><span style="color: #FF0000; "><br />eternal</span><span style="color: #0000FF; ">="false"</span><span style="color: #FF0000; "><br />timeToIdleSeconds</span><span style="color: #0000FF; ">="100"</span><span style="color: #FF0000; "><br />timeToLiveSeconds</span><span style="color: #0000FF; ">="100"</span><span style="color: #FF0000; "><br />overflowToDisk</span><span style="color: #0000FF; ">="false"</span><span style="color: #0000FF; ">></span><span style="color: #000000; "><br /></span><span style="color: #0000FF; "><</span><span style="color: #800000; ">cacheEventListenerFactory </span><span style="color: #FF0000; ">class</span><span style="color: #0000FF; ">="net.sf.ehcache.distribution.RMICacheReplicatorFactory"</span><span style="color: #FF0000; "><br />properties</span><span style="color: #0000FF; ">="replicateAsynchronously=true,<br />replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true "</span><span style="color: #0000FF; ">/></span><span style="color: #000000; "><br /></span><span style="color: #0000FF; "></</span><span style="color: #800000; ">cache</span><span style="color: #0000FF; ">></span></div><br /> nameQ缓存名U。通常为缓存对象的cdQ非严格标准Q?br /> <br /> maxElementsInMemoryQ设|基于内存的~存可存攑֯象的最大数目?br /> <br /> maxElementsOnDiskQ设|基于硬盘的~存可存攑֯象的最大数目?br /> <br /> eternalQ如果ؓtrueQ表C对象永q不会过期,此时会忽略timeToIdleSeconds和timeToLiveSeconds属性,默认为false;<br /> <br /> timeToIdleSecondsQ?讑֮允许对象处于I闲状态的最长时_以秒为单位。当对象自从最q一ơ被讉K后,如果处于I闲状态的旉过了timeToIdleSeconds属性|q个对象׃q期。当对象q期QEHCache把它从~存中清I。只有当eternal属性ؓfalseQ该属性才有效。如果该属性gؓ0Q则表示对象可以无限期地处于I闲状态?br /> <br /> timeToLiveSecondsQ设定对象允许存在于~存中的最长时_以秒为单位。当对象自从被存攑ֈ~存中后Q如果处于缓存中的时间超q了 timeToLiveSeconds属性|q个对象׃q期。当对象q期QEHCache把它从~存中清除。只有当eternal属性ؓfalseQ该属性才有效。如果该属性gؓ0Q则表示对象可以无限期地存在于缓存中。timeToLiveSeconds必须大于timeToIdleSeconds属性,才有意义?br /> <br /> overflowToDiskQ如果ؓtrue,表示当基于内存的~存中的对象数目辑ֈ了maxElementsInMemory界限后,会把益出的对象写到基于硬盘的~存中?br /> <br /> class – 使用net.sf.ehcache.distribution.RMICacheReplicatorFactory<br /> <br /> q个工厂支持以下属性:<br /> replicatePuts=true | false – 当一个新元素增加到缓存中的时候是否要复制到其他的peers. 默认是true?br /> replicateUpdates=true | false – 当一个已l在~存中存在的元素被覆盖时是否要进行复制。默认是true?br /> replicateRemovals= true | false – 当元素移除的时候是否进行复制。默认是true?br /> replicateAsynchronously=true | false – 复制方式是异步的Q指定ؓtrueӞq是同步的(指定为falseӞ。默认是true?br /> replicateUpdatesViaCopy=true | false – 当一个元素被拯到其他的cache中时是否q行复制Q指定ؓtrue时ؓ复制Q,默认是true?br /> <br /> 你可以用ehcache的默认行Z而减配|的工作量,默认的行为是以异步的方式复制每g事;你可以像下面的例子一样减RMICacheReplicatorFactory的属性配|:<br /> <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; "><!--</span><span style="color: #008000; "> Sample cache named sampleCache4. All missing RMICacheReplicatorFactory properties default to true </span><span style="color: #008000; ">--></span><span style="color: #000000; "><br /></span><span style="color: #0000FF; "><</span><span style="color: #800000; ">cache </span><span style="color: #FF0000; ">name</span><span style="color: #0000FF; ">="sampleCache4"</span><span style="color: #FF0000; "><br />maxElementsInMemory</span><span style="color: #0000FF; ">="10"</span><span style="color: #FF0000; "><br />eternal</span><span style="color: #0000FF; ">="true"</span><span style="color: #FF0000; "><br />overflowToDisk</span><span style="color: #0000FF; ">="false"</span><span style="color: #FF0000; "><br />memoryStoreEvictionPolicy</span><span style="color: #0000FF; ">="LFU"</span><span style="color: #0000FF; ">></span><span style="color: #000000; "><br /></span><span style="color: #0000FF; "><</span><span style="color: #800000; ">cacheEventListenerFactory </span><span style="color: #FF0000; ">class</span><span style="color: #0000FF; ">="net.sf.ehcache.distribution.RMICacheReplicatorFactory"</span><span style="color: #0000FF; ">/></span><span style="color: #000000; "><br /></span><span style="color: #0000FF; "></</span><span style="color: #800000; ">cache</span><span style="color: #0000FF; ">></span></div><br /><strong>常见的问题Windows上的Tomcat</strong><br /> <br /> 有一个Tomcat或者是JDK的bugQ在tomcat启动时如果tomcat的安装\径中有空格的话,在启动时RMI监听器会p|。参见http://archives.java.sun.com/cgi-bin/wa?A2=ind0205&L=rmi-users&P=797和http://www.ontotext.com/kim/doc/sys-doc/faq-howto-bugs/known-bugs.html?br /> <br /> ׃在Windows上安装Tomcat默认是装?#8220;Program Files”文g多w的,所以这个问题经常发生?br /> <br /> <strong>q播L</strong><br /> <br /> 自动的peer discovery与广播息息相兟뀂广播可能被路由LQ像Xen和VMWareq种虚拟化的技术也可以Lq播。如果这些都打开了,你可能还在要你的网卡的相关配置打开?br /> <br /> 一个简单的办法可以告诉q播是否有效Q那是使用ehcache remote debugger来看“心蟩”是否可用?br /> <br /> <strong>q播传播的不够远或是传得太远</strong><br /> <br /> 你可以通过讄badly misnamed time to live来控制广播传播的距离。用q播IP协议ӞtimeToLive的值指的是数据包可以传递的域或是范围。约定如下:<br /> <br /> 0是限制在同一个服务器<br />1是限制在同一个子|?br />32是限制在同一个网?br />64是限制在同一个region<br />128是限制在同一个大z?br />255是不限制<br /> <br /> 译者按Q上面这些资料翻译的不够准确Q请读者自行寻扑֎文理解吧?br /> <br /> 在Java实现中默认值是1Q也是在同一个子|中传播。改变timeToLive属性可以限制或是扩展传播的范围?br /> <br /> 原文地址?http://ehcache.sourceforge.net/documentation/distributed_caching.html<img src ="http://www.aygfsteel.com/paulwong/aggbug/369948.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2012-02-14 15:46 <a href="http://www.aygfsteel.com/paulwong/archive/2012/02/14/369948.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>优化E序之前Q可用Jamon来监你的Spring应用http://www.aygfsteel.com/paulwong/archive/2012/01/25/368882.htmlpaulwongpaulwongWed, 25 Jan 2012 08:32:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/01/25/368882.htmlhttp://www.aygfsteel.com/paulwong/comments/368882.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/01/25/368882.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/368882.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/368882.html*作者:张荣?ahuaxuan)
    *2007-8-15
    *转蝲h明出处及作?
    */

    前两天在看Spring内置的拦截器的时候,发现了一个之前没有注意的c:org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptorQ好奇心促我上|查了一下这个jamon。大概看了一下之后发现这个玩意还真挺好用的而且挺重要的Q而且现在国内对它的介l也很少Q所以写了一文章和大家分n?

    一QJamon介:
    Jamon的全名是QJava Application Monitor。它是一个小巧的Q免费的Q高性能的,U程安全的性能监测工具。它可以用来定pȝ的性能瓉Q也可以用来监视用户和应用程序之间的交互情况?Jamon主要是用来检jee的应用程序。它最新的版本?.1Q可以用?.4以上的jdk上?

    二,jamon导入C的应用程序中?
    首先下蝲jamon的开发包Q见我的附gQ同时你也可以去Sourceforge上自׃载。Sourceforge的下载地址为http://jamonapi.sourceforge.net。解压之后可以得C个jar包和一个war包。jar包是自己会用到的Q而war包是一个例子(不要看q个例子Q待会也要把它导入到目中)。把war包之间丢到服务器上,讉KQlocalhost:8080/jamon可以看到这个例子了Q这个例子是一个简单的性能监控pȝ?

    接着把例子中的所有的包都导入到项目中Qƈ把war包中的jsp和imagesq有css都考到目中,比如新徏一个目录叫monitorQ它和WEB-INF是同U目录)?

    三,正确配置自己的应?
    我们在性能监测的时候最监测的就是页面的讉K率和cMҎ的访问率。所以在q一部分主要讲解一下如何监自q面和类中方法的讉K?

    1Q?自q面讉K?
    首先我们需要在web.xml中添加一个filterQ这个filter是用来判断哪些面需要被监视的,如下所C:
    <filter>
            
    <filter-name>JAMonFilter</filter-name>
            
    <filter-class>com.easywebwork.filter.EasyPageMonFilter</filter-class>
        
    </filter>
        
    <filter-mapping>
            
    <filter-name>JAMonFilter</filter-name>
            
    <url-pattern>/*</url-pattern>
        
    </filter-mapping>

    接下来我们看看这个filter的写法:

    /**
    *
    @author 张荣华(ahuaxuanQ?br /> *
    *
    @since 2007-8-13
    */

    public class PageMonFilter extends JAMonFilter{

    private static final long serialVersionUID = 5746197114960908454L;

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    Monitor allPages
    = MonitorFactory.start(new MonKeyImp("org.easywebwork.allPages",getURI(request),"ms."));
    //q里是我们要监视的所有的面的配|?/span>
    Monitor monitor = MonitorFactory.start(getURI(request));
    //q里是我们要监视的某个面的配|?/span>
    try {
    filterChain.doFilter(request, response);
    }
    finally {
    monitor.stop();
    allPages.stop();
    }

    }


    protected String getURI(ServletRequest request) {
    if (request instanceof HttpServletRequest) {
    return ((HttpServletRequest) request).getRequestURI();
    }
    else {
    return "Not an HttpServletRequest";
    }

    }


    private FilterConfig filterConfig = null;

    }
    }

    q个cȝ上去很简单,其实也挺单的Q就是得到uriQ然后把它注册到MonitorFactorycM。这样只要我们去讉K刚才创徏的monitor目录下的jsp可以看到性能监测面了?

    2Q?接下来我们看看在使用spring的情况下如何监测一个bean的方法调用?br />Spring也提供了对Jamon的支?spring支持的东西还真多?Q也是文章开头提出的那个拦截器,Zl我们的bean加上拦截器,我们在spring的applicationcontext配置文g中加入如下语句:

    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="beanNames">
    <list>
    <value>userService</value>
    </list>
    </property>
    <property name="interceptorNames">
    <list>
    <value>jamonInterceptor</value>
    </list>
    </property>
    </bean>

    <bean id="jamonInterceptor" class="org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor">
    </bean>

    上面q个是典型的spring的aop的配|,如果对spring的aop配置不了解的可以ȝ一下spring中文文档Q当然如果不想了解的话即使直接把q段配置拷到自己的项目中也是可以直接使用的?

    q有一个步骤就是在你的log4j.properties中加入这句代码:

    log4j.logger.org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor = TRACE


    如果没有q一行,那么q个拦截器是不会把方法调用的信息向MonitorFactory注册的?

    只需要这些步骤,userservice中的Ҏ在调用的时候就可以被拦截,然后其注册到MonitorFactory中去了?

    所有的配置完成之后我们来看一下效果吧:
    http://www.iteye.com/topics/download/b2bac96e-6c18-4340-b7e0-f84c7bb6adca从这个图上我们可以看刎ͼ所有页面被讉K的次敎ͼUserService中的getAllUsers被调用的ơ数Q最双的是讉K旉。这只是整个囄一部分Q当然这个页面中也包括每一个页面被讉K的次数和W一ơ访问的旉{等。下载附件运行,可以看到所有的面了?

    三,ȝ
    Ҏ以上的步骤,我们可以监我们的E序了,应用E序中哪些页面被讉K的多Q哪些页面被讉K的少Q哪些方法被讉K的多Q哪些方法被讉K的少Q以及访问高峰期集中在什么时间等{,有了q些参数Q我们更可以有针Ҏ的对应用程序进行优化了Q比如说某个面讉K比较频繁Q我可以用ehcache或oscachel这个页面做一个缓存。如果某个方法的讉K比较频繁那就看看q个Ҏ能否q一步优化,是需要异步,q是需要缓存,q是需要其他等{,M有了jamon可以l我们带来更多的便捷Q既可以让我们知道我们的客户的行为,也可以让我们知道我们开发的E序?#8220;能力”?

    其实本文提供的只是对面和方法调用的监控Q但是jamon可以提供更多功能Q比如说sql语句的监控等{,q就需要我们共同去发掘了?

    附g中包括了一个easywebwork的例子,我把jamon导入到这个例子工E中去,大家可以直接下蝲q行观看效果。Easywebwork是一个旨在减webwork2.2.xpd的xml配置文g的项目?br />
  • JamonSample.rar (3.7 MB)
  • 描述: ׃上传文g大小有限Ӟ所以需要同学们自己d一下jar包: spring,common-logging,log4j,common-collections activation, common-lang

     

  • lib.rar (3.3 MB)
  • 描述: W二l包包括 spring,common-logging,log4j,common-collections activation, common-lang

     



  • paulwong 2012-01-25 16:32 发表评论
    ]]>
    memcache-client-forjava http://www.aygfsteel.com/paulwong/archive/2012/01/24/368871.htmlpaulwongpaulwongTue, 24 Jan 2012 12:34:00 GMThttp://www.aygfsteel.com/paulwong/archive/2012/01/24/368871.htmlhttp://www.aygfsteel.com/paulwong/comments/368871.htmlhttp://www.aygfsteel.com/paulwong/archive/2012/01/24/368871.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/368871.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/368871.htmlhttp://code.google.com/p/memcache-client-forjava/
    http://marc.iteye.com/blog/28700
    http://www.jayxu.com/2010/06/09/2342/
    http://www.iteye.com/topic/128458
    http://code.google.com/p/xmemcached/wiki/User_Guide_zh



    paulwong 2012-01-24 20:34 发表评论
    ]]>
    EhCache ~存pȝ?/title><link>http://www.aygfsteel.com/paulwong/archive/2012/01/24/368869.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 24 Jan 2012 12:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2012/01/24/368869.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/368869.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2012/01/24/368869.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/368869.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/368869.html</trackback:ping><description><![CDATA[     摘要: EhCache 是一个纯Java的进E内~存框架Q具有快速、精q等特点Q是Hibernate中默认的CacheProvider? 下图?EhCache 在应用程序中的位|: EhCache 的主要特性有Q? 1. 快?2. ?3. 多种~存{略4. ~存数据有两U:内存和磁盘,因此无需担心定w问题5. ~存数据会在虚拟机重启的q程中写入磁?. 可以通过RMI、可插入API...  <a href='http://www.aygfsteel.com/paulwong/archive/2012/01/24/368869.html'>阅读全文</a><img src ="http://www.aygfsteel.com/paulwong/aggbug/368869.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2012-01-24 20:32 <a href="http://www.aygfsteel.com/paulwong/archive/2012/01/24/368869.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ָɽ</a>| <a href="http://" target="_blank">ʲ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">鴨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">޽</a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˳</a>| <a href="http://" target="_blank">¹</a>| <a href="http://" target="_blank">ͩ</a>| <a href="http://" target="_blank">ƺ</a>| <a href="http://" target="_blank">ͺ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ǫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">齭</a>| <a href="http://" target="_blank">³</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">׸</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ϰ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȫ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>