Building asynchronous tasks with returning results
One of the first challenges you will face if you have never worked with asynchronous tasks is: how on Earth do you return results from an asynchronous task if you don't know when the execution will end?
Well, this recipe show you how. AsyncResponse
for the win!
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:
package com.eldermoraes.ch09.async.result; /** * * @author eldermoraes */ public class User { private Long id; private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName...