首页 > 代码库 > 仿照Android的池化技术
仿照Android的池化技术
/** * 仿照Android池化技术 * @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(); private 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 = http://www.mamicode.com/value;>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。