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
Month: December 2023
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
Using @Value example
In all my previous posts under Lombok, I used Pojo classes as an example. All these Pojo classes are mutable since they have setter and getter method. In this post, I will show with example how to create an immutable class. To create an immutable class, we annotate a Pojo class with “@Value” annotation and…… Continue reading Using @Value example
Using @Getter(lazy=true) example
In this post under Lombok, I will explain with example the purpose of “@Getter(lazy=true)” annotation. In many cases, the values of Pojo class instance variables are fixed. In some cases, these values have to be computed at runtime. We can add a getter method which when called first time, will compute the value once and…… Continue reading Using @Getter(lazy=true) example
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
Generating an TOTP
In this post I will show with example how to generate TOTP. TOTP is based on HOTP but instead of using counter, TOTP uses the current time as the counter in addition to secret key So TOTP = HOTP(secret key, current time). Similar to HOTP in client server scenario both client and server has to…… Continue reading Generating an TOTP