999精品在线视频,手机成人午夜在线视频,久久不卡国产精品无码,中日无码在线观看,成人av手机在线观看,日韩精品亚洲一区中文字幕,亚洲av无码人妻,四虎国产在线观看 ?

The Research on building cache for Android platform using soft references

2013-04-29 03:43:54YongpanShengRuitingDai
無(wú)線互聯(lián)科技 2013年7期
關(guān)鍵詞:研究

Yongpan Sheng Ruiting Dai

Abstract:Along with the mobile platform increasing development,Android operating system has become the dominant operating system on mobile platforms.As the result of the limitation of Android system computing environment and network resources,it is especially important to apply Cache technology to improve the efficiency of data access.In this paper,a detail study is made on soft reference technology of mobile platform and soft reference strategy is proposed to build a cache on the Android platform application.It has increased the use of system memory efficiently and data access performance.Meanwhile soft reference object can help the Dalvik virtual machine to manage memory and eliminate potential memory leaks well.

Keyword:Android;Soft Reference;Cache

In the Android System Computing Environment, system memory and the bandwidth of the wireless communication is very limited.This requires that the Android client should try to reduce the commnunication overhead over the wireless and conservation memory resources when in use. Caching techniques, as the classical techniques of improving data access performance, have achieved successful application in the field of computer communication[1]. When introduced Caching techniques into the Android mobile computing environment,it is conducive not only to reduce the overhead of the Android client in the wireless communication procedure, but also to improve the hit rate of the valid data in the memory.

Soft references is a high level of Java objects. It is very suitable for creating the cache to store some expensive common resources in the Android client environment.The client can check the availability of the cached data before performing query operations[2].In general,data can be directly obtained in the repetitive operations.While data out of the range of cache management need to be loaded asynchronously over wireless network.

1 The characteristics of soft references

A soft reference is the object referenced by SoftReference with a relatively long life cycle.In the Android environment,only when system is starved of memory will it release the soft reference object.So we can use them to store some expensive resources which need to be loaded asynchronously,such as online picture data in which each soft reference object that has stored picture data existing in the entire application lifecycle is also a java object[3]. Besides,when the system is out of memory,the content cached by soft reference can be released and recycled by Dalvik virtual machine.

Dalvik virtual machine often perform garbage collection operations according to Mark-Sweep algorithm, which causes the uncertainty of running time. However,provided that the a object which reference exists will be in the memory all the time.If more and more objects like this exist,which even beyond the memory capacity of Dalvik virtual machine,the system will throw OOM(Out of Memory) error.It is more flexible to control the lifecycle of less important object in the application through soft references.When the system is out of memory,these objects can be recycled temporarily.If the system memory is also lacking after the Dalvik virtual machine has finished all the recycling project,the Dalvik will throw OOM error.

2 The management of soft references

We can flexibly control the liftcycle of Java object in the application with soft references.The method of using it is shown in Java code below:

MyObject ref=new MyObject();//Create an object of type MyObject

SoftReference softRef=new SoftReference(ref);//Create a soft reference of ref object

ref=null;//Eliminate the strong reference to the MyObject object

MyObject anthorRef=(MyObject)softRef.get();

//Obtain the object through soft reference

After executing the above code,there are two ways to reference the MyObject object.One is for the soft reference of softRef and the other one is for the strong reference of ref means MyObject object is a strongly reachable object.When the ref is set to null,the garbage collection thread in the Dalvik will make a distinction between softly reachable object and other strongly reachable object in the system. Whats more,before the Dalvik throws OOM,the garbage collection thread would recycle the unused softly reachable object as preferentially as possible. And the Dalvik will reserve the newly created softly reachable object as much as possible.Before recycling the MyObject object,the get() method of softRef obtains the strongly reference of MyObject object. And after recycling,the get() method returns null[4].

Besides the particularity of soft reference object,SoftReference object has the generality of Java object.When the softly reachable object reclaimed, this SoftReference object is already not worthy to exist although the get() method of SoftReference object returns null.That is because the soft reference object it keeps has alreay not existed. At this time,an appropriate clearance mechanism is needed to avoid the “new” memory leaks caused by a large number of SoftReference objects.The Java.long.ref package provides ReferenceQueue object.The methods of using it is shown in Java code below:

ReferenceQueue refQueue=new ReferenceQueue();//Create a reference queue

SoftReference softRef=new SoftReference(ref,refQueue);

//Add the soft reference into the reference queue

while(null !=(refQueue.poll())){

// clear ref object

}

After executing the above code,with the soft reachable object stored by this SoftReference object being recycled by Dalvik garbage collection thread,SoftRefrence object referenced by softRef is added to ReferenceQueue[5].ReferenceQueue is a queue, which stores SoftReference objects that lost reference object.This queue has the characteristic of “FIFO”.We can call the poll() method to check whether the soft reference objects it concerns is recycled or not. If the queue is empty, it returns null,otherwise it returns a SoftReference object at the head of the queue. Meanwhile we can check which SoftReference has been recycled and then clean up the SoftReference objects which lost reference object.

3 The implementation strategy of soft reference cache in Android platform application

In the Android application of C/S structure,the client usually needs to obtain pictures and other data information from the server.However,loading pictures is a time consuming and traffic consuming process.If the issue is not properly handled,it will make users feel stuck and the application is not friendly.There may be a lot of repetitive operations when loading pictures. From this angle embarking, there is no need to refetch the network pictures from the same URL address.We can keep some expensive image resources in memory and use LRU algorithm to optimize storage.Besides,the other image resources can be saved in the SDCard of client.As the pictures take up only a little space in the SDCard,it not only ensures the speed of loading pictures but also saves the traffic of the wireless communication. This caching strategy applys to the asynchronous image loading by ListView.Moreover,It can futher optimize memory allocation and better avoid throwing ANR(Application Not Responsed) exception information by the application,which is good for the interaction with users.The specific implementation can be divided into several steps below:

(1)Create buffer cache in memory.We can use LinkedHashMap to create strongly reference cache used to store URLs of network pictures and corresponding Bitmap objects.Because LinkedHashMap store data in the bottom,it has a higher efficiency to access data. ConcurrentHashMap is used to store URLs of pictures and corresponding Bitmap soft reference objects,which has a guarantee for synchronizing data and accessing safely to threads.

(2)The implementation of load pictures asynchronously.Android provides AsyncTask class which encapsulate basic models used in asynchronous operations.We can execute pictures request operation in doInBackground() method.After loading,the AsyncTasks built-in handler send message to main thread and all the UI operation achieved in onPostExecute() method.

(3)Design callback and execute LRU replacement algorithm.Two methods is needed to included in designed callback interface.One is for pass URLs of pictures and loaded Bitmap objects to UI thread,the other one is for replace inactive picture resource in strongly reference cache to soft reference cache through executing LRU algorithm.

We can achieve ListView loading network pictures asynchronously with cache,those concrete procedures are as shown below.

4 Conclusion

Soft references, which have strong reference function,can be used in the Android computing environment with limited system memory and wireless broadband to cache some expensive resources that need to be loaded asynchronously.It can improve the utilization of memory and the performance of accessing data.This paper focuses on the characteristics and management methods of soft references.For the Android platform application, the implementation strategy of soft reference in loading pictures asynchronously by ListView is proposed. There is still one thing should be concerned that although soft reference can control the life cycle of Java object in the application flexibly,it may not effective to android client application which is very dependent on cache in performance.Furthermore,it cannot replace complex caching framework that can provide flexible termination period.

[References]

[1]張昊,潘祖烈.Java軟引用防止內(nèi)存泄漏技術(shù)的研究[J].安徽教育學(xué)院學(xué)報(bào),2006,24(6):42-45.

[2]楊安寧,周瑩,呂康,等.一種Android平臺(tái)GIS軟件的新型數(shù)據(jù)緩存策略的實(shí)現(xiàn)[J].計(jì)算機(jī)與現(xiàn)代化,2012,(10):46-49.

[3]焦忭忭.移動(dòng)數(shù)據(jù)庫(kù)在管理信息系統(tǒng)中的應(yīng)用研究[D].武漢理工大學(xué),2006.

[4]曾麗娟,婁松濤.移動(dòng)客戶機(jī)中緩存技術(shù)的應(yīng)用研究[J].電腦知識(shí)與技術(shù)(學(xué)術(shù)交流),2007,3(18):1657-1658.

[5]周毅敏,陳榕.Dalvik虛擬機(jī)進(jìn)程模型分析[J].計(jì)算機(jī)技術(shù)與發(fā)展,2010,20(2):83-86.

猜你喜歡
研究
FMS與YBT相關(guān)性的實(shí)證研究
2020年國(guó)內(nèi)翻譯研究述評(píng)
遼代千人邑研究述論
視錯(cuò)覺(jué)在平面設(shè)計(jì)中的應(yīng)用與研究
科技傳播(2019年22期)2020-01-14 03:06:54
關(guān)于遼朝“一國(guó)兩制”研究的回顧與思考
EMA伺服控制系統(tǒng)研究
基于聲、光、磁、觸摸多功能控制的研究
電子制作(2018年11期)2018-08-04 03:26:04
新版C-NCAP側(cè)面碰撞假人損傷研究
關(guān)于反傾銷(xiāo)會(huì)計(jì)研究的思考
焊接膜層脫落的攻關(guān)研究
電子制作(2017年23期)2017-02-02 07:17:19
主站蜘蛛池模板: 国产成人精品一区二区| 久久人与动人物A级毛片| 欧美激情,国产精品| 国产高潮流白浆视频| 国产亚洲欧美在线专区| 免费av一区二区三区在线| 综合色区亚洲熟妇在线| 亚洲狼网站狼狼鲁亚洲下载| 国产精品 欧美激情 在线播放| 国产成人精品视频一区二区电影 | 成人亚洲天堂| 免费在线色| 潮喷在线无码白浆| 91口爆吞精国产对白第三集 | 最新亚洲人成网站在线观看| 免费无码又爽又刺激高| 国产女人爽到高潮的免费视频 | h视频在线播放| 波多野结衣亚洲一区| 亚洲黄色片免费看| 久久香蕉国产线| 亚洲成人免费在线| 欧美成人h精品网站| 日韩高清中文字幕| 亚洲最大情网站在线观看| 国产真实乱了在线播放| 免费AV在线播放观看18禁强制| av无码一区二区三区在线| 粉嫩国产白浆在线观看| 欧美视频在线观看第一页| 久久国产拍爱| 成人av专区精品无码国产| 免费人成黄页在线观看国产| 中国国产A一级毛片| 高清无码不卡视频| 久久久久人妻一区精品色奶水| 日韩在线第三页| 亚洲人人视频| 午夜久久影院| 欧亚日韩Av| 精品偷拍一区二区| 伊人久久综在合线亚洲91| 久久久久亚洲AV成人网站软件| 国产成人调教在线视频| 综合五月天网| 国产大片喷水在线在线视频 | 福利一区在线| yy6080理论大片一级久久| 欧美一级高清片欧美国产欧美| 久久婷婷国产综合尤物精品| 99尹人香蕉国产免费天天拍| 四虎永久在线精品国产免费| 亚洲第一极品精品无码| 亚洲人成网18禁| 国产三区二区| 久久亚洲天堂| 亚洲欧美另类中文字幕| 欧美区国产区| 国产精品性| 成人国产精品一级毛片天堂| 最新日韩AV网址在线观看| 伊人久久精品亚洲午夜| 国产亚洲精品97在线观看| 日韩美女福利视频| 久久精品国产精品青草app| 国产一级无码不卡视频| 内射人妻无码色AV天堂| 在线亚洲小视频| 最新国产麻豆aⅴ精品无| 亚洲一区二区约美女探花| 极品性荡少妇一区二区色欲| 亚洲欧洲免费视频| 真实国产乱子伦高清| 波多野结衣国产精品| 伊人久久大香线蕉成人综合网| 国产精品手机在线播放| 成人一区在线| 国产成人综合在线观看| 日韩欧美中文字幕一本| 亚洲91在线精品| 欧美在线视频a| 一区二区三区四区日韩|