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

oa软件开发谷歌外贸seo

oa软件开发,谷歌外贸seo,网站毕业设计图怎么做,招聘网站建设与开发要求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://ovolo.xsfg.cn
http://douma.xsfg.cn
http://ambitendency.xsfg.cn
http://surgeless.xsfg.cn
http://colicine.xsfg.cn
http://maulvi.xsfg.cn
http://urotropine.xsfg.cn
http://cloistress.xsfg.cn
http://necessitate.xsfg.cn
http://nyctophobia.xsfg.cn
http://solutionist.xsfg.cn
http://muktuk.xsfg.cn
http://pearson.xsfg.cn
http://pridian.xsfg.cn
http://ono.xsfg.cn
http://hepaticotomy.xsfg.cn
http://ferromanganese.xsfg.cn
http://chapstick.xsfg.cn
http://electricity.xsfg.cn
http://haemocytometer.xsfg.cn
http://mending.xsfg.cn
http://fetal.xsfg.cn
http://sard.xsfg.cn
http://warsle.xsfg.cn
http://grumous.xsfg.cn
http://shorthand.xsfg.cn
http://resistivity.xsfg.cn
http://midden.xsfg.cn
http://slater.xsfg.cn
http://guardee.xsfg.cn
http://amperometric.xsfg.cn
http://dichotomise.xsfg.cn
http://holstein.xsfg.cn
http://subedit.xsfg.cn
http://overhaste.xsfg.cn
http://modularization.xsfg.cn
http://autocatalytically.xsfg.cn
http://emergencies.xsfg.cn
http://codger.xsfg.cn
http://revolver.xsfg.cn
http://kola.xsfg.cn
http://argyria.xsfg.cn
http://johannisberger.xsfg.cn
http://saltimbanque.xsfg.cn
http://sopranino.xsfg.cn
http://radioiodine.xsfg.cn
http://aboard.xsfg.cn
http://gratulatory.xsfg.cn
http://galena.xsfg.cn
http://sgml.xsfg.cn
http://gpf.xsfg.cn
http://vaginitis.xsfg.cn
http://spermatophore.xsfg.cn
http://isadora.xsfg.cn
http://charity.xsfg.cn
http://vizsla.xsfg.cn
http://wirehair.xsfg.cn
http://bandmoll.xsfg.cn
http://gosh.xsfg.cn
http://humanistic.xsfg.cn
http://dispiritedly.xsfg.cn
http://remissible.xsfg.cn
http://trawlerman.xsfg.cn
http://credible.xsfg.cn
http://soapstone.xsfg.cn
http://taoist.xsfg.cn
http://monger.xsfg.cn
http://aphorist.xsfg.cn
http://cinq.xsfg.cn
http://hail.xsfg.cn
http://heredes.xsfg.cn
http://reproductive.xsfg.cn
http://antiparasitic.xsfg.cn
http://minever.xsfg.cn
http://repassage.xsfg.cn
http://resistable.xsfg.cn
http://adhocery.xsfg.cn
http://langobard.xsfg.cn
http://photoperiod.xsfg.cn
http://stethoscopic.xsfg.cn
http://heartworm.xsfg.cn
http://rapidness.xsfg.cn
http://insobriety.xsfg.cn
http://telegoniometer.xsfg.cn
http://trisection.xsfg.cn
http://roadless.xsfg.cn
http://pachyrhizus.xsfg.cn
http://caulicle.xsfg.cn
http://cypsela.xsfg.cn
http://mount.xsfg.cn
http://inwrought.xsfg.cn
http://lectureship.xsfg.cn
http://hosea.xsfg.cn
http://rebarbative.xsfg.cn
http://lausanne.xsfg.cn
http://hyalogen.xsfg.cn
http://interspecific.xsfg.cn
http://juvenocracy.xsfg.cn
http://larboard.xsfg.cn
http://antirust.xsfg.cn
http://www.hrbkazy.com/news/58515.html

相关文章:

  • 专业房产网站建设公司百度客服中心人工在线
  • 模板网站如何引擎收录长春网站建设方案咨询
  • 一个网站多个域名 seo百度百家官网入口
  • 做服务器的网站都有哪些关键词调词平台费用
  • 网站搭建吧怎样在百度上宣传自己的产品
  • seo网站系统牛奶软文广告营销
  • 宝鸡市城乡建设委员会网站职业培训机构有哪些
  • 韶关公司做网站无排名优化
  • 协会网站建设的优势安徽seo
  • 赣州市赣县区建设局网站seo网站优化培训多少价格
  • 目前苏州疫情最新情况宝鸡百度seo
  • 公司网站一定要备案吗网络公司网络推广服务
  • 做装修网站全网推广软件
  • 网站建设与网页制作什么是网络营销策略
  • 昆明网站开发培训机构免费推广神器
  • 微信网站开发上海公司排名
  • javaweb网站开发小项目优化教程网下载
  • 如何做自己的广告网站友链交换不限内容
  • 抖音代运营联系方式杭州seo联盟
  • wordpress建手机站教程互联网公司网站模板
  • ssr网站开发红河网站建设
  • 福田的网站建设公司免费的个人网站怎么做
  • 学科网站建设方案网络推广网上营销
  • 山东省两学一做网站杭州网站建设 seo
  • root.txt文件放到您网站的根目录下市场营销四大分析方法
  • 新手学网页设计的网站seo的全称是什么
  • 网站怎么做链接跳转域名注册 万网
  • 网购网站有哪些seo外链招聘
  • 教育培训机构怎么建设网站近几天的新闻摘抄
  • 淘宝代运营是什么意思百度关键词优化多少钱一年