A standard application job is to read, process, and write data. If we want to make these operations asynchronous, we should use asynchronous reading, processing, and writing.
For example, if an asynchronous function is blocked, we write excellent code:
readData.get() and blocked,
processData.get() and blocked,
writeData.get() and blocked immediately.
And we get synchronous code at the output. It’s not asynchronous and not easy to use.
Let’s look at a typical task where we have asynchronous data reading and then want to process data in three threads:
We don't need many threads to wait for the results of the reading. We just want to get data. This data should be processed, and processing is a resource-consuming task in terms of CPU, and it would be good to parallelize it. We say: “Read data. Once you do it, process them in three threads, then combine the results of execution and write data.” And we would like to do this as asynchronous operations.
The original article can be found here.
Interested in learning how to program with Java or in upgrading your Java programming skills? Check out our trainings.