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
Adding StatisticsListener (using xml configuration)
In this post under Spring Retry, I will show with example how to add Spring Retry’s StatisticsListener class into your application. StatisticsListener class provided by Spring Retry framework collects statistics of a particular retry operations. The statistics information involves1) Abort Count –> How many times the retry was aborted2) Complete Count –> How many times…… Continue reading Adding StatisticsListener (using xml configuration)
Creating Custom RetryListener (using xml configuration)
In this post under Spring Retry, I will show with example how to add RetryListener to our Spring Retry code. RetryListener interface will help us to react to events like (react before first retry attempt, react after every failed retry attempt, react after final retry attempt). RetryListener interface has the below three interface methods.1) void…… Continue reading Creating Custom RetryListener (using xml configuration)
Spring Retry simple example (using interceptor)
In this post under Spring Retry, I will explain how to configure Spring Retry framework into your application using Spring AOP with simple example. At minimum, you need the below jars in your classpath1) spring-retry-1.3.1.jar2) commons-logging-1.2.jar3) spring-core-4.3.22.RELEASE.jar4) spring-aop-4.3.22.REELEASE.jar5) spring-beans-4.3.22.RELEASE.jar6) spring-context-4.3.22.RELEASE.jar7) spring-expression-4.3.22.RELEASE.jar8) aspectjweaver-1.8.9.jar For our example we will use the below service class Service1 public class…… Continue reading Spring Retry simple example (using interceptor)
Setting private fields of a class for unit testing
In this post under Powermock, I will with example show how to set private fields of a class for unit testing. For example, consider you have a class as shown below to be tested Class To Be Tested package package5; import java.util.Date; import java.util.Random; public class Example5 { private Random random = new Random(); public…… Continue reading Setting private fields of a class for unit testing
Creating custom logic for Disposable
In this post under RxJava, I will show with example how to add custom logic when a subscription between Observable and Observer is being disposed. You can add custom logic in Disposable only if you are creating an Observable using callback style. In my previous post under RxJava I have shown you how to create…… Continue reading Creating custom logic for Disposable
Using CompositeDisposable
In this post under RxJava, I will show with an example the purpose and how to use the CompositeDisposable class. When you have multiple subscriptions like shown below, we get a multiple Disposable object one for each subscription. Observable<Long> observable1 = Observable.interval(1000, TimeUnit.MILLISECONDS); Disposable disposable1 = observable1.subscribe((t) -> System.out.println(“Observable1: ” + t)); Observable<Long> observable2 =…… Continue reading Using CompositeDisposable
Disposing an automatically created Observer
In this post, I will explain how to dispose an automatically created Observer. In all my previous posts, when I provide the below code snippet, it was creating an Observer internally that will compose these lambda callback functions provided as arguments to the “subscribe” method. observable.subscribe(t -> System.out.println(t), t -> t.printStackTrace(), () -> System.out.println(“Complete”)); In…… Continue reading Disposing an automatically created Observer
Creating and Disposing an Observer Manually
In this post under RxJava, I will explain how to create and dispose an Observer manually. Till now in all my previous posts under RxJava, I was not creating and disposing an Observer manually. The Observer was created internally by RxJava. All I was doing was providing callback functions for onNext,onComplete, and onError events as…… Continue reading Creating and Disposing an Observer Manually