Another way of creating asynchronous services is using Future<T> and CallableFuture<T> as return values. Let us create these asynchronous APIs in our services by following these steps:
- Open the EmployeeServiceImpl implementation class. Study the service methods readEmployees() and readEmployee(id). The readEmployees() passes the whole employee record retrieval transaction to the @Controller in a CompletableFuture<Employee> form. On the other side, the readEmployee(id) passes the whole result as a Future<Employee> object.
- Add another service class, namely DepartmentService, with the following templates:
public interface DepartmentService { public CompletableFuture<List<Department>> readDepartments(); public void addDepartment(DepartmentForm ...