当前位置: 首页 > news >正文

重庆最新新闻5条/优化网站排名公司

重庆最新新闻5条,优化网站排名公司,ui网页设计培训学校,如何做网络营销网站2019独角兽企业重金招聘Python工程师标准>>> Ehcache中可以使用Cache来保存需要缓存的对像,但需要把对象封装在Element的实例里。 往Cache中添加对像: CacheManager manager CacheManager.newInstance("src/config/cache.xml");…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

        Ehcache中可以使用Cache来保存需要缓存的对像,但需要把对象封装在Element的实例里。

   往Cache中添加对像:  

CacheManager manager = CacheManager.newInstance("src/config/cache.xml");   
manager.addCache("testCache");
Cache cache = singletonManager.getCache("testCache");
Element element = new Element("key", "value");      
cache.put(element);

  

   相应源码:

       /*** Put an element in the cache.* <p/>* Resets the access statistics on the element, which would be the case if it has previously been* gotten from a cache, and is now being put back.* <p/>* Also notifies the CacheEventListener that:* <ul>* <li>the element was put, but only if the Element was actually put.* <li>if the element exists in the cache, that an update has occurred, even if the element would be expired* if it was requested* </ul>* <p/>* Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.* This exception should be caught in those circumstances.** @param element A cache Element. If Serializable it can fully participate in replication and the DiskStore. If it is*                <code>null</code> or the key is <code>null</code>, it is ignored as a NOOP.* @throws IllegalStateException if the cache is not {@link Status#STATUS_ALIVE}* @throws CacheException*/public final void put(Element element) throws IllegalArgumentException, IllegalStateException,CacheException {put(element, false);}

   Element UML类图:

 140749_rAab_1050156.png     

         构造一个Element对象很简单,Cache没有什么复杂的操作。但看似简单的put操作,它的实现是还有点复杂。

  Step 1:  开发者调用Cache的put方法。

cache.put(element);

   Step 2:  对应的源码

public final void put(Element element) throws IllegalArgumentException, IllegalStateException,CacheException {put(element, false);}

 Step 3:  默认情况下doNotNotifyCacheReplicators的值是false.暂时先不讨论集群。

     private void putAll(Collection<Element> elements, boolean doNotNotifyCacheReplicators) throws IllegalArgumentException,

            IllegalStateException, CacheException {

        putAllInternal(elements, doNotNotifyCacheReplicators);

    }

Step 4:  具体实现细节。 可以大概看一下,今天我们主要分析一下 putObserver这个变量的作用。

private void putInternal(Element element, boolean doNotNotifyCacheReplicators, boolean useCacheWriter) {putObserver.begin();if (useCacheWriter) {initialiseCacheWriterManager(true);}checkStatus();if (disabled) {putObserver.end(PutOutcome.IGNORED);return;}if (element == null) {if (doNotNotifyCacheReplicators) {LOG.debug("Element from replicated put is null. This happens because the element is a SoftReference" +" and it has been collected. Increase heap memory on the JVM or set -Xms to be the same as " +"-Xmx to avoid this problem.");}putObserver.end(PutOutcome.IGNORED);return;}if (element.getObjectKey() == null) {putObserver.end(PutOutcome.IGNORED);return;}element.resetAccessStatistics();applyDefaultsToElementWithoutLifespanSet(element);backOffIfDiskSpoolFull();element.updateUpdateStatistics();boolean elementExists = false;if (useCacheWriter) {boolean notifyListeners = true;try {elementExists = !compoundStore.putWithWriter(element, cacheWriterManager);} catch (StoreUpdateException e) {elementExists = e.isUpdate();notifyListeners = configuration.getCacheWriterConfiguration().getNotifyListenersOnException();RuntimeException cause = e.getCause();if (cause instanceof CacheWriterManagerException) {throw ((CacheWriterManagerException)cause).getCause();}throw cause;} finally {if (notifyListeners) {notifyPutInternalListeners(element, doNotNotifyCacheReplicators, elementExists);}}} else {elementExists = !compoundStore.put(element);notifyPutInternalListeners(element, doNotNotifyCacheReplicators, elementExists);}

      

   putObserver,只看名字,第一反应就知道,这也许是一个观察者。Right! 

   private final OperationObserver<PutOutcome> putObserver = operation(PutOutcome.class).named("put").of(this).tag("cache").build();

 附上相关调用的UML类图,方便大家理解。

161715_ziqk_1050156.png

        Cache类依赖StatisticBuilder的operation()方法,通过StatisticsManager来创建GeneralOperationStatistic类的一个实例。此实例实现了OperationObserver接口的begin()和end()方法。

 putObserver.begin(); 

170949_zS67_1050156.png

 注:个人觉得这个地方的代码其实是运行不到的,因为它的addDerivedStatistic方法也没有被调用到。或者是我疏忽了哪个地方,还请知情人士贡献一下。get的被用到了,下节我会详细介绍。  


putObserver.end(elementExists ? PutOutcome.UPDATED : PutOutcome.ADDED);

对应的操作:

171009_nkcj_1050156.png

注: increment()是org.terracotta.statistics.jsr166e.LongAdder类下面基于CAS原理实现的一个线程安全的自增方法。感兴趣的朋友可以reference这个link:

 http://grepcode.com/file/repo1.maven.org/maven2/net.sf.ehcache/ehcache/2.7.2/org/terracotta/statistics/jsr166e/LongAdder.java#LongAdder.add%28long%29

     

       从我们的调查结果中可以看出,putObserver主要目的是统计put操作时ADDED,UPDATED,IGNORED的个数。 虽然结果很简单,但更多的是让我们知道了它的设计理念以及思想。虽然实现起来很复杂,但代码看起来还是那么的简洁。

         

        

 

 


转载于:https://my.oschina.net/zookeeper/blog/186004

http://www.lbrq.cn/news/1555993.html

相关文章:

  • 旅游景点/做seo需要用到什么软件
  • 网站建设的流程图示/什么是seo
  • 哪些公司做企业网站/seo网站排名优化服务
  • 网站制作手机模板/网络营销知识点
  • 快速搭建网站 优帮云/百度优化
  • 网站开发的人/商业软文怎么写
  • 做外贸最好的网站建设/今日军事新闻最新消息新闻
  • 网站管理系统后台/深圳关键词快速排名
  • 杭州网站建设杭州手机网站建设/电脑课程培训零基础
  • 泰州谁会建网站/软件制作
  • python 做网站开发吗/手机网站seo免费软件
  • 惠州双语网站建设费用/神马关键词快速排名软件
  • 做苗木比较好的网站/长沙关键词优化新行情报价
  • 网站首页菜单栏模块怎么做的/电商网站运营
  • 园区建设网站的方案/企业网络搭建方案
  • 南昌网站排名优化价格/黑帽seo之搜索引擎
  • 网站商城建设员招聘/培训心得体会总结简短
  • 域名有了怎么建网站/公司怎么推广网络营销
  • 做二手元器件那个网站查价格/代运营公司前十名
  • 手机访问网站自动跳转/东莞网络营销代运营
  • 做网站需要硬件设施/凡科建站和华为云哪个好
  • 有哪些网站可以用/seo关键词选取工具
  • 公司网站设计师/重庆人力资源和社会保障网
  • 网站建设请示报告/建设企业营销型网站
  • 长安做英文网站/外包公司是什么意思
  • 有官网建手机网站/志鸿优化设计官网
  • 手机可以登录国家开发银行网站吗/营销方案怎么写?
  • 丹东 建设集团 招聘信息网站/免费推广网站地址大全
  • 三个小伙毕业了做购物网站的电视剧/网站收录免费咨询
  • 做视频网站怎么盈利模式/怎样在网上推广
  • nodejs 中间件
  • 从需求到部署全套方案:餐饮服务许可证数据可视化分析系统的大数据技术实战
  • 自然语言处理NLP---预训练模型与 BERT
  • 矿物分类案列 (一)六种方法对数据的填充
  • 三、memblock 内存分配器
  • 测试18种RAG技术,找出最优方案(四)