Using Future<T> and CallableFuture<T>
When it comes to propagating the result of an asynchronous service transaction, there are two popular APIs that are responsible for wrapping both the task and its result, namely Future<T> and CallableFuture<T>. These APIs can manage any asynchronous executions with or without a successful completion. This recipe will demonstrate the usage of these two containers and will also compare and contrast the two APIs.
Getting started
Open ch08 again and add the following @Service methods that return Future<T> and CallableFuture<T> task containers.
How to do it...
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
EmployeeServiceImplimplementation class. Study the service methodsreadEmployees()andreadEmployee(id). ThereadEmployees()passes the whole employee record retrieval...