How to do it...

  1. 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;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    }
  1. Then, we call UserBean to return a User instance:
@Statelesspublic class UserBean {    public User getUser() {        long id = new Date().getTime();        try {            TimeUnit.SECONDS.sleep(5);            return new User(id, "User " + id);        } catch (InterruptedException ex) {            System.err.println(ex.getMessage());            return new User(id, "Error " + id);        }    }}
  1. And finally, we create an async endpoint to call ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.