/** * Emulate Android Pooling technology * @author Fgtian * */public class Objectcachetest {public static class Objectitem {private static int Spoolsize = 0;private static final int max_cache = 10;private static final Object spoollock = new Object ();p rivate static Objectitem SPool = null;private Objectitem mnext = null;private int mvalue;public static Objectitem obtain () {synchronized (Spoollock) {if (null! = SPool) {Objectitem item = Spool;spool = Item.mnext;item.mnext = Null;--spoolsize;return item;}} return new Objectitem ();} public static Objectitem obtain (int value) {synchronized (Spoollock) {if (null! = SPool) {Objectitem item = Spool;spool = Item.mnext;item.mnext = Null;--spoolsize;item.mvalue = Value;return item;}} return new Objectitem (value);} public void Recycle () {synchronized (Spoollock) {if (Spoolsize < Max_cache) {Mvalue = 0;this.mnext = Spool;spool = This ; spoolsize++;}}} Public Objectitem () {}public objectitem (int value) {mvalue = value;} @Overridepublic String toString () {return string.valueof (Mvalue);}} public static final void main (string[] args) {Objectitem item1 = Objectitem.obtain (1); item1.recycle (); Objectitem item2 = O Bjectitem.obtain (3); if (item1 = = item2) {System.out.println ("YES, use the same OBJECT");} else {System.out.println (" ERROR ");}}}