Configuring Generic Object Pool

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

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

Setting startup timeout

In this post under TestContainers, I will show with example how to setup startup timeout. Whenever we start a container whether through programmatically or through Docker Desktop or any other container management software, it takes time to start. TestContainers to figure out whether a container has started or not, it waits for 60 sec so…… Continue reading Setting startup timeout

Retrieve environment values present in file

In previous posts under DotEnv, whenever we called static “load” method on “DotEnv” class it used to load system environment values in addition to environmentvalues present in .env or .env file with custom name. What if we want only the environment values present in the file and not the system environment values. There is way…… Continue reading Retrieve environment values present in file

Accessing an non existing environment key

In this post under DotEnv, I will show with example how to handle retrieving values of environment keys that doesn’t exist. Below is the main class for your reference. Main class 1 package defaultPackage;2 3 import io.github.cdimascio.dotenv.Dotenv;4 5 public class Example6 {6 public static void main(String[] args) {7 Dotenv dotenv = Dotenv.load();8 String value =…… Continue reading Accessing an non existing environment key

Changing scopes to @Component annotated class

In this post under Spring Core, I will show with example how to change the scope of class annotated with “@Component” annotation. By default whenever we annotate a class with “@Component” annotation the scope of the bean is set to “singleton”. We can change this by the help of “@Scope” annotation which is also applied…… Continue reading Changing scopes to @Component annotated class