common-pool2

对象池common-pool2源码分析之对象状态

梦想与她 提交于 2019-12-17 20:42:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 对象池common-pool2源码分析 对象池common-pool2策略分析 从前两篇的分析中可以看出对象池中的对象会被激活,钝化,销毁等 ,那么做这些操作的对象需要满足什么条件呢 ,与这些操作之后相对应的对象的状态是什么样的呢? 首先从PooledObjectState开始分析 public enum PooledObjectState { /** * In the queue, not in use. */ IDLE, /** * In use. */ ALLOCATED, /** * In the queue, currently being tested for possible eviction. */ EVICTION, /** * Not in the queue, currently being tested for possible eviction. An * attempt to borrow the object was made while being tested which removed it * from the queue. It should be returned to the head of the queue once * eviction testing

对象池common-pool2策略分析

人走茶凉 提交于 2019-12-17 20:28:28
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 上一篇: 对象池common-pool2分析 common-pool2策略 上一篇对象池common-pool2分析从三个主要的接口进行分析,这一篇将对源码进行详细的分析,力图找出对象池的管理策略.从之前的分析可以看出ObjectPool定义了对象池需要实现的功能,所以重点分析ObjectPool. GenericObjectPool:一般对象池 Generic KeyedObjectPool:可以根据key分组的对象池 SoftReferenceObjectPool:软引用对象池. GenericObjectPool public GenericObjectPool(PooledObjectFactory<T> factory, GenericObjectPoolConfig config) { super(config, ONAME_BASE, config.getJmxNamePrefix()); if (factory == null) { jmxUnregister(); // tidy up throw new IllegalArgumentException("factory may not be null"); } this.factory = factory; /

对象池common-pool2源码分析

喜夏-厌秋 提交于 2019-12-17 20:21:30
【推荐】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