Non-blocking tasks using async method invocation pattern
The asynchronous method invocation pattern is a way to solve the challenge of not penalizing the main process thread with possibly time-consuming tasks.
Motivation
Asynchronous method invocation patterns introduce the ability to receive a result by a callback from an asynchronously running task without blocking the main process thread. The pattern presents the threading model and level of parallelism for processing the required task types. The task results are processed by dedicated callback handlers and provided to the main process regardless of the task’s execution time. These handlers may already belong to the main process.
Sample code
Let us look at a trivial scenario of several vehicle temperature sensors required to provide results to the driver, which is the client (Example 6.4):
public static void main(String[] args) throws Exception { System.out.println("Async method...