Reactive Programming in Java: How, Why, and Is It Worth Doing? History of Multithreading
History of Multithreading
Difficult to write, difficult to debug, difficult to test.
- Future interface:
- V get()
- boolean cancel()
- boolean isCancelled()
- boolean isDone()
- Callable interface
Then a method ‘get’ appeared in the Future interface. It blocks a call until the completion of the calculation. For example, we have Future which returns data from the DB, and we address the get method:
Returning to the metaphor of manager and employees, we set a task, did some job, and then waited for the task to be completed. And what if we need to pass the result of this job to another person? We have already reviewed such a case: do the job, pass the results, and then get back. In the case of parallelism, there is no such possibility.
The Future capabilities are very limited. For instance, we can find out if this task was executed:
Future f = getDBData();
if (!f.isDone) doOtherJob();
If the task is not completed yet, we can do something else. Anyway, we’ll miss this point: either the task is not completed, or it is, but we are busy with other things. Points of synchronization are not very clear here.
The Future interface had minimal capabilities in Java 5 and was not easy to use.
Interested in learning how to program with Java or in upgrading your Java programming skills? Check out our trainings.