b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

weakreference java内存泄露分析,java弱引用(weakreferen(5)

电脑杂谈  发布时间:2017-05-27 23:01:53  来源:网络整理

privateReferenceQueue queue=newReferenceQueue();

// Strong Reference numberpublicSoftHashMap(){this(100); }

publicSoftHashMap(inthardSize){ HARD_SIZE=hardSize; }publicObject get(Object key){

Object result=null;//We get the SoftReference represented by that key

SoftReference soft_ref=(SoftReference)hash.get(key);if(soft_ref!=null){

//From the SoftReference we get the value, which can be//null if it was not in the map, or it was removed in

//the processQueue() method defined belowresult=soft_ref.get();

if(result==null){//If the value has been garbage collected, remove the

//entry from the HashMap. hash.remove(key);

}else {//We now add this object to the beginning of the hard

//reference queue.One reference can occur more than//once, because lookups of the FIFO queue are slow, so

//we don't want to search through it each time to remove//duplicates.

// keep recent use object in memory hardCache.addFirst(result);

if(hardCache.size()>HARD_SIZE){//Remove the last entry if list longer than HARD_SIZE

hardCache.removeLast(); }

} }

returnresult; }

/**We define our own subclass of SoftReference which contains

not only the value but also the key to make it easier to findthe entry in the HashMap after it's been garbage collected.*/

privatestaticclassSoftValueextendsSoftReference{privatefinalObject key;//always make data member final

/**Did you know that an outer class can access private datamembers and methods of an inner class?I didn't know that!

I thought it was only the inner class who could access theouter class's private information.An outer class can also


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-49607-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...