对象池common-pool2源码分析
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Apache common-pool2提供了一个通用的对象池技术的实现。 common-pool2主要围绕三个接口来实现,ObjectPool、PooledObject、PooledObjectFactory。由 PooledObjectFactory创建的对象,经 PooledObject包装后放入 ObjectPool。 1.ObjectPool对象池 ObjectPool:对象池,负责存放管理对象. 官方例子: http://commons.apache.org/proper/commons-pool/examples.html ReaderUtil readerUtil = new ReaderUtil(new GenericObjectPool<StringBuffer>(new StringBufferFactory())); 先从GenericObjectPool开始分析 成员变量: 重要的成员变量为: allObjects和idleObjects. /* * All of the objects currently associated with this pool in any state. It * excludes objects that have been destroyed. The