亚洲免费av电影一区二区三区,日韩爱爱视频,51精品视频一区二区三区,91视频爱爱,日韩欧美在线播放视频,中文字幕少妇AV,亚洲电影中文字幕,久久久久亚洲av成人网址,久久综合视频网站,国产在线不卡免费播放

        ?

        The Research on building cache for Android platform using soft references

        2013-04-29 03:43:54YongpanShengRuitingDai
        無線互聯(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].安徽教育學院學報,2006,24(6):42-45.

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

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

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

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

        猜你喜歡
        周瑩武漢理工大學客戶機
        Reducing the global cancer burden with gastrointestinal screening: China’s 30 years practice
        購物撿漏,低折扣拿好貨
        家庭百事通(2020年2期)2020-03-19 08:46:59
        《武漢理工大學學報(交通科學與工程版)》征稿簡則
        《武漢理工大學學報(交通科學與工程版)》征稿簡則
        《那年花開月正圓》那些戳破人物性格的臺詞
        Lanterne-volant
        法語學習(2016年2期)2016-04-16 15:50:09
        The Application of Victory—learning in Chunks in English Teaching in Vocational School
        幾何形態(tài)和視覺感知的探討
        9 Respiratory System
        瘦客戶機:安全與便捷的選擇
        日本高清乱码中文字幕| 亚洲 美腿 欧美 偷拍| 亚洲一区二区三区麻豆 | 国产自拍高清在线观看| 日韩av东京社区男人的天堂| 午夜大片又黄又爽大片app| baoyu网址国产最新| 91精品国产综合久久精品密臀| 在线亚洲高清揄拍自拍一品区| 国产精品视频二区不卡| 国产成人福利在线视频不卡 | 男女视频网站在线观看| 国产精品人人做人人爽| 天码av无码一区二区三区四区| 色哟哟av网站在线观看| 蜜桃视频羞羞在线观看| 亚洲av无码久久精品色欲| 国产剧情国产精品一区| 亚洲国产精品一区二区第一| 少妇免费av一区二区三区久久| 风韵多水的老熟妇| 亚洲国产精品久久久久秋霞1 | 真实国产老熟女无套中出| 国产人成午夜免电影观看| 亚洲高清自偷揄拍自拍| 桃红色精品国产亚洲av| 欧美日韩色另类综合| 91精品国产免费久久久久久青草| 国产午夜视频高清在线观看| 亚洲无码在线播放| 在线永久看片免费的视频| 午夜一区二区三区在线视频| 一区二区三区中文字幕脱狱者| 和外国人做人爱视频| 亚洲—本道中文字幕久久66| 午夜一区二区三区福利视频| 久久婷婷五月综合色欧美| 人妻丰满熟妇AV无码区HD| 日本不卡的一区二区三区| 欧美群妇大交群| 久久无码av三级|