Checking the status of asynchronous tasks
Beyond executing asynchronous tasks, which opens up a lot of possibilities, sometimes it is useful and necessary to get the status of those tasks.
For example, you could use it as a check the time elapsed on each task stage. You should also think about logging and monitoring.
This recipe will show you an easy way to do this.
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...
- Let's first create a
User
POJO:
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(String name) ...