In this post under Apache Pool, I will show how to create GenericObjectPool instance with custom configuration In all post under Apache Pool, I showed how to create GenericObjectPool using default configuration. When we use the below code snippet, we are creating an object pool with default configuration. GenericObjectPool<Thread> genericObjectPool = new GenericObjectPool<Thread>(threadPooledObjectFactory); To change…… Continue reading Configuring Generic Object Pool
Category: Apache Pool
Creating a soft reference object pool
In this post under Apache Pool, we will explain with example how to create soft reference object pool. For our example we will create the below thread factory class that extends Apache Pool framework’s “BasePooledObjectFactory” class. package package6;import org.apache.commons.pool2.BasePooledObjectFactory;import org.apache.commons.pool2.PooledObject;import org.apache.commons.pool2.impl.DefaultPooledObject;public class ThreadPooledObjectFactory extends BasePooledObjectFactory<Thread> { private int count = 0; @Override public Thread create()…… Continue reading Creating a soft reference object pool
Getting number of active and idle objects in object pool
In this post under Apache Pool, I will explain with example how to retrieve number of active and idle objects in object pool. For our example I will create the below factory class which extends Apache Pool’s “BasePooledObjectFactory” class. package package5;import org.apache.commons.pool2.BasePooledObjectFactory;import org.apache.commons.pool2.PooledObject;import org.apache.commons.pool2.impl.DefaultPooledObject;public class ThreadPooledObjectFactory extends BasePooledObjectFactory<Thread> { private int count = 0; @Override…… Continue reading Getting number of active and idle objects in object pool
BaseKeyedPooledObjectFactory example
In the previous post under Apache Pool, I showed you with example how to use “KeyedPooledObjectFactory” interface to create an object pool. In this post I will show how to use “BaseKeyedPooledObjectFactory” class provided Apache Pool framework. We created our own implementation of “KeyedPooledObjectFactory” interface in the previous post as shown below. I have added…… Continue reading BaseKeyedPooledObjectFactory example
KeyedPooledObjectFactory Example
In previous post under Apache Pool I showed you how to create a pool of objects. The pool of objects are not classified based on specific criteria. So as a result if you are expecting that Apache Pool should return an object based on specific criteria is not possible. To solve this requirement Apache Pool…… Continue reading KeyedPooledObjectFactory Example
BasePooledObjectFactory class Example
In the previous post under Apache Pool, I showed you with example how to use PooledObjectFactory interface to create an object pool. In this post I will show how to use “BasePooledObjectFactory” class provided Apache Pool framework. We created our own implementation of PooledObjectFactory interface in the previous post as shown below. I have added…… Continue reading BasePooledObjectFactory class Example
Creating Object Pool
In this post under Apache Pool, I will show with simple example how to create a pool of objects. We need the below jar in our classpath to use Apache Pool frameworkcommons-pool2 We need to know about 3 Apache Pool interface1) ObjectPool –> manages pool of objects2) PooledObjectFactory –> takes responsibility of creating and destroying…… Continue reading Creating Object Pool