CompletableFuture with timeout

Two CompletableFutures  can be combined to timeout the CompletableFuture with the business logic like below:  package competablefuture; import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class CompletableFutureSample { static ScheduledExecutorService pool = Executors.newScheduledThreadPool(4); public static CompletableFuture executeAsyncTimed(Duration duration) { final CompletableFuture asyncTimedFuture = new CompletableFuture<>(); pool.schedule(() -> asyncTimedFuture.completeExceptionally(new TimeoutException()), duration.toMillis(), … More CompletableFuture with timeout

JBOSS Wildfly XADataSourceClass is undefined

Sometimes, the server gives the following error after configuring the driver for the database: ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906: Error during crash recovery: java:/PostgresXADS (IJ031084: Unable to create connection): javax.resource.ResourceException: IJ031084: Unable to create connection at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory.getXAManagedConnection( at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory$1$ at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory$1$ at Method) at at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory$ at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory$ at Method) at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory.createManagedConnection( … More JBOSS Wildfly XADataSourceClass is undefined

RxJava Mapping functions

RxJava has several mapping functions. These functions transforms the emitted items to another form or value. The mapping functions are: map flatMap concatMap flatMapIterable switchMap   map function maps the items to another value of the same or different type @Test public void testobservableMap() { List<Integer> list = new ArrayList<>(); IntStream.range(0, 1000).forEach(list::add); Observable<Integer> observableFromCollection = … More RxJava Mapping functions

RxJava Operations on Observables

Filtering and other operations on Observables If only a subset of elements in a stream is needed, a filter can be used to eliminate the items not needed and let the observable emit only desired elements. @Test public void testCreateObservableFromCollectionWithFilter() { List<Integer> list = new ArrayList<>(); IntStream.range(0, 1000).forEach(list::add); Observable<Integer> observableFromCollection = Observable.from(list).filter(e -> e%2==0); observableFromCollection.subscribe(new … More RxJava Operations on Observables

Creating Observables and Subscribers in RxJava

RxJava is a very useful library for asynchronous and event-based programming, also called reactive programming. There are two main actors in RxJava: Observables — An object that emits a stream of data or events Observers/Subscribers — An object that acts upon the emitted data.   An observer is an object which know how to act upon 3 sort of … More Creating Observables and Subscribers in RxJava