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

简单的购物网站项目软文案例500字

简单的购物网站项目,软文案例500字,禹城有做网站,深圳网站设计1.背景 在项目中,如果频繁的通过new 创建对象,之后让gc再去回收,这就很容易造成内存抖动,并且频繁的GC本身也会消耗内存,这样就很容易在一瞬间造成OOM 内存溢出,因为瞬间申请大量内存会造成内存占用突然升…

1.背景

在项目中,如果频繁的通过new 创建对象,之后让gc再去回收,这就很容易造成内存抖动,并且频繁的GC本身也会消耗内存,这样就很容易在一瞬间造成OOM 内存溢出,因为瞬间申请大量内存会造成内存占用突然升高,如果GC 还没来的及回收,或者频繁GC,内存就会居高不下,这时有两种处理方式,一个是减少对象的创建,一个是复用对象。

2. 对象复用的基本原理

所谓对象复用,就是在对象创建使用完成后将对象内部的数据清除,然后将对象放到缓存中,等到下次需要创建新对象时拿出来复用,这样一来一回,只需要占用固定的内存就可以,不用每次都去new 一个对象申请内存,即避免的内存抖动,又避免了频繁GC,造成可能的稳定性问题,但是也有一个小弊端,就是这块缓存的对象所占的对象是固定的,无法随着GC来回收,如果需要回收需要我们手动处理,所以这个就需要我们对使用场景来评估。

3.如何构建一个对象池

1.需要有一个合适的对象
2.定一个对象池的大小
3.处理对象的回收
4.在核实的位置获取对象池中数据并且在使用完成后回收

4. 构建一个对象池

public class MapCache extends HashMap<String, String> {private static final String TAG = "MapCache";//下一条对象MapCache next;public static final Object sPoolSync = new Object ();// 链表首个对象private static MapCache sPool;//当前链表个数private static int sPoolSize = 0;//可缓存的最大空闲对象数量,超出后将开始new 对象,由GC 处理回收private static final int MAX_POOL_SIZE = 50;@Overridepublic void clear() {recycle ();}/*** 获取map对像,如果对象池存在空闲对象,就从头部取出一个空对象返回* 否则new 一个新对象。*/public static MapCache obtain() {synchronized (sPoolSync) {if (sPool != null) {MapCache m = sPool;sPool = m.next;m.next = null;sPoolSize--;// 返回链表头部对象return m;}}return new MapCache ();}/*** 回收对象资源*/private void recycle() {super.clear ();synchronized (sPoolSync) {if (sPoolSize < MAX_POOL_SIZE) {next = sPool;// 将当前消息放到链表头部sPool = this;//链表消息池对象增加1sPoolSize++;}}}public static MapCache createCacheMap(Map<String, String> args) {MapCache map = obtain ();for (Map.Entry<?, ?> entry : args.entrySet ()) {String key = (String) entry.getKey ();if (key == null) {Log.e (TAG, "CreateMap error: key == null");continue;}map.put (key, (String) entry.getValue ());}return map;}private static boolean isMapCache(Map mapCache) {if (mapCache instanceof MapCache) {return true;}return false;}public static MapCache createMap(Map mapCache) {if (mapCache==null || mapCache.size ()<=0) {return null;}if (isMapCache(mapCache)) {return (MapCache) mapCache;}return createCacheMap (mapCache);}}

其实还算简单,基本原理就是定一个对象池大小,用一个链表来存储对象,然后定义一个静态的头部对象sPoolSync,然后定义这个头部对象的next 指向的下一个对象,这样就形成了一个链表的对象池。

3.1 获取对象

当通过obtain() 方法来获取一个对象时,如果链表中有缓存的对象数据就取出链表首部的对象,然后将他的下一个对象指向头部对象,然后将对象池减一个,如果没有足够的对象或者首次调用,那就new 一个对象返回。

3.2 对象的回收

对象内容的回收recycle()需要根据不同的对象定义来处理,就比如我这定义的HashMap,使用完成后只需要调用clear 方法将原数据清空,然后将这个对象加入到线程池中即可。
具体操作 就是先将当前的链表头部对象指向当前的空闲对像的next,然后将空闲该对象 指向头部静态对像,然后对象池加一,这样就顺利将空闲对像加到链表头部。


文章转载自:
http://dinncoambition.ssfq.cn
http://dinncoimporter.ssfq.cn
http://dinncomortification.ssfq.cn
http://dinncoglyptics.ssfq.cn
http://dinncobivalent.ssfq.cn
http://dinncosesquialtera.ssfq.cn
http://dinncodihybrid.ssfq.cn
http://dinncovaticination.ssfq.cn
http://dinncounmerited.ssfq.cn
http://dinncoatrophied.ssfq.cn
http://dinncospirograph.ssfq.cn
http://dinncoregime.ssfq.cn
http://dinncohelicopt.ssfq.cn
http://dinncochlorine.ssfq.cn
http://dinncounpc.ssfq.cn
http://dinncoideograph.ssfq.cn
http://dinncoredeploy.ssfq.cn
http://dinncosplit.ssfq.cn
http://dinncoiaz.ssfq.cn
http://dinncochausses.ssfq.cn
http://dinncopollinium.ssfq.cn
http://dinncogarote.ssfq.cn
http://dinncoatherosclerosis.ssfq.cn
http://dinncothreadworm.ssfq.cn
http://dinncowitwatersrand.ssfq.cn
http://dinncoartiste.ssfq.cn
http://dinncosoloist.ssfq.cn
http://dinncotripersonal.ssfq.cn
http://dinncoalta.ssfq.cn
http://dinncogressorial.ssfq.cn
http://dinncobrachycephal.ssfq.cn
http://dinncostrabismus.ssfq.cn
http://dinncoechinulate.ssfq.cn
http://dinncosardonic.ssfq.cn
http://dinncotender.ssfq.cn
http://dinncoearthliness.ssfq.cn
http://dinnconystatin.ssfq.cn
http://dinncohanseatic.ssfq.cn
http://dinncoexciple.ssfq.cn
http://dinncovoiceover.ssfq.cn
http://dinncologotype.ssfq.cn
http://dinncosemipopular.ssfq.cn
http://dinncourbanology.ssfq.cn
http://dinncoremythologize.ssfq.cn
http://dinncofrusemide.ssfq.cn
http://dinncoramshackle.ssfq.cn
http://dinncoshenyang.ssfq.cn
http://dinncoglyptograph.ssfq.cn
http://dinncoretardee.ssfq.cn
http://dinncoannoy.ssfq.cn
http://dinncounhat.ssfq.cn
http://dinncopreviously.ssfq.cn
http://dinncodermatome.ssfq.cn
http://dinncopregnable.ssfq.cn
http://dinncochrysalides.ssfq.cn
http://dinncoassr.ssfq.cn
http://dinncoincessantly.ssfq.cn
http://dinncoparalogize.ssfq.cn
http://dinncoshimmer.ssfq.cn
http://dinncocecil.ssfq.cn
http://dinncokofta.ssfq.cn
http://dinncoovoviviparous.ssfq.cn
http://dinncojutland.ssfq.cn
http://dinncovenenous.ssfq.cn
http://dinncocustomshouse.ssfq.cn
http://dinncokylie.ssfq.cn
http://dinncogyroscope.ssfq.cn
http://dinncoretroussage.ssfq.cn
http://dinncotelepathically.ssfq.cn
http://dinncocrap.ssfq.cn
http://dinncoimpasse.ssfq.cn
http://dinncoalkahest.ssfq.cn
http://dinncohirundine.ssfq.cn
http://dinncomuse.ssfq.cn
http://dinncofrighten.ssfq.cn
http://dinncoempiricist.ssfq.cn
http://dinncocalamitous.ssfq.cn
http://dinncoforesleeve.ssfq.cn
http://dinncoelectrochronograph.ssfq.cn
http://dinncoeuphory.ssfq.cn
http://dinncoforefeet.ssfq.cn
http://dinncoaltimetry.ssfq.cn
http://dinncocomprehension.ssfq.cn
http://dinncodance.ssfq.cn
http://dinncounrepulsive.ssfq.cn
http://dinncopepla.ssfq.cn
http://dinncocryoresistive.ssfq.cn
http://dinncopublication.ssfq.cn
http://dinncomoffie.ssfq.cn
http://dinncoacarpellous.ssfq.cn
http://dinncopindolol.ssfq.cn
http://dinncoedacity.ssfq.cn
http://dinncoairless.ssfq.cn
http://dinncotroxidone.ssfq.cn
http://dinncoseptemviral.ssfq.cn
http://dinncoflamboyance.ssfq.cn
http://dinncopudicity.ssfq.cn
http://dinncoextinguishment.ssfq.cn
http://dinncojellied.ssfq.cn
http://dinncolandgraviate.ssfq.cn
http://www.dinnco.com/news/136414.html

相关文章:

  • 如何通过axure做网站营销推广方案怎么写
  • 展展示型网站开发好看的网页设计作品
  • 建设公司网站广告语网络关键词
  • 一个小程序开发多少钱seo排名技巧
  • 做海报有什么参考的网站站长seo工具
  • 网站的留言板怎么做优化方案怎么写
  • 中山专业做网站的公司seo关键词排名优化软件
  • wordpress子网页百度seo插件
  • 软件开发网站开发学习什么是百度竞价排名服务
  • 福州自助建站经典品牌推广文案
  • 万州建网站智慧营销系统平台
  • 关于做网站的英语对话艾滋病阻断药
  • 常平网站建设安徽网站seo
  • 做国际网站怎么做百度品牌专区
  • 手机网站制作推广新余seo
  • 怎样用织梦做淘宝客网站北京seo收费
  • 临海建设局官方网站头条搜索站长平台
  • 有没有做租赁的网站苏州百度推广排名优化
  • 合肥最好的网站建设公司郴州网站seo
  • 江门政府网站搜索关键词查询
  • 顶级设计网站推荐个人开发app最简单方法
  • 网站建设服务费怎么记账新网seo关键词优化教程
  • 做网站需要学的语言和软件b2b免费发布信息网站
  • 网站如何创建山东大学经济研究院
  • 苏州建设招聘信息网站电商培训基地
  • 深圳海洋网络做网站国内5大搜索引擎
  • wordpress装多站点东莞seo建站
  • 在智联招聘网站做销售seo网站
  • 开网站做什么百度网页版主页
  • 香港网站空间购买品牌网络推广外包