How to meet such an expert?? Here is an implementation of a simple cache, quite a bull fork! See for yourself, there's only 50 lines of code.
Excerpt from: http://www.oschina.net/code/snippet_55577_3887
ImportJava.util.Map;ImportJava.util.WeakHashMap;ImportJava.util.concurrent.ConcurrentHashMap;ImportJava.util.concurrent.locks.Lock;ImportJava.util.concurrent.locks.ReentrantLock; Public Final classSimplecache<k,v> { Private FinalLock lock =NewReentrantlock (); Private Final intmaxcapacity; Private FinalMap<k,v>Eden; Private FinalMap<k,v>Perm; PublicSimplecache (intmaxcapacity) { This. maxcapacity =maxcapacity; This. Eden =NewConcurrenthashmap<k,v>(maxcapacity); This. perm=NewWeakhashmap<k,v>(maxcapacity); } Publicv get (k k) {v v= This. Eden.get (k); if(v = =NULL) {lock.lock (); Try{v= This. Perm.get (k); }finally{lock.unlock (); } if(V! =NULL) { This. Eden.put (k, v); } } returnv; } Public voidput (k K, v V) {if( This. Eden.size () >=maxcapacity) {Lock.lock (); Try{ This. Perm.putall ( This. Eden); }finally{lock.unlock (); } This. Eden.clear (); } This. Eden.put (k, v); }}
50 lines of code to implement caching, Java memory model principle