From the course: Advanced Java: Threads and Concurrency
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Future - Java Tutorial
From the course: Advanced Java: Threads and Concurrency
Future
- [Instructor] If you order a pizza online that will take 30 minutes or more to deliver on a busy day, would you sit and wait for it or do some other work at home in the meantime? To make the most of your time, you'll probably do other work. And once the pizza arrives, you enjoy it. Similarly, in asynchronous programming, while a time consuming task like a read from a database over the network is going on, the program can execute other tasks. The result of the database read will be available sometime in the future, and once results are available, they can be processed as required. The main idea is for an application to continue doing things that it can without waiting for results of the other. This way, program execution becomes more efficient. So the main requirement here is to be able to represent a value that will be available in future. In other words, a promise that guarantees that results will be returned in future. This is where the future object plugs in. The…