Using lambdas and CompletableFuture to improve reactive applications
The Java language always had the reputation of being a verbose language. But since the advent of lambdas, this issue has improved a lot.
We can use lambdas and also bring CompletableFuture
to the party to improve not only the coding, but also the behavior of reactive applications. This recipe will show you how.
Getting ready
Let's first add our Java EE 8 dependency:
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>8.0</version> <scope>provided</scope> </dependency>
How to do it...
- First, we create a
User
POJO:
public class User implements Serializable{ private Long id; private String name; public User(long id, String name){ this.id = id; this.name = name; } public Long getId() { return id; } public void setId(Long id) { this.id = id...