The future is also a Java 1.5 brought in the product, but in the past so many years the actual code has little direct contact, about it is hidden in a variety of out-of-the-box framework silently serve us. The future itself does not represent multi-threading, but rather represents the result of an asynchronous computation, one that will be expected later, as far as the real result is unknown. Before you want to get a Runnable in other threads, the result is a lot of twists and turns, with the future combined with the callable behind it all becomes simple.
Compare the following concepts around Java 1.5
Callable is equivalent to the previous Runnable, except that callable has a return value.
Executeservice.submit (callable): The future is similar to the previous Thread (runnable)
Only the former is executed immediately after submit, the result is obtained through get (), the latter is started with the start () method, and the runnable is no result. If you don't want to care about future results, you can executeservice.submit (runnable)
Only the future that is returned after callable is committed (to the thread pool) can have results, so the following code will never wait for the result
future<string> future = new Futuretask<> ((), "never");
String result = Future.get ();
The most understandable future basic usage code is as follows: Read the full text >>
Consolidating the use of Java future