Start United States USA — software Future, A Token of Task Submission

Future, A Token of Task Submission

258
0
TEILEN

The concurrency package is the boss when it’s come to asynchronous programming. Of course, this is the continuation of my previous articles on asynchronous …
Join the DZone community and get the full member experience. I believe, the title is very abstract but clearly explains the purpose. The concurrency package is the boss when it’s come to asynchronous programming. Of course, this is the continuation of my previous articles on asynchronous programming. We have seen creating Threads and make use of Executor Framework for the Thread management. Also, We look at how to submit a task and how is it processed internally in the executor. But we haven’t seen how to check the status or getting the result etc. That’s the purpose that brought us the Future Interface. Future lies in the same package as other concurrency class that is java.util.concurrent. And It’s available since Java 1.5. In simple words, a Future is a token of task creation and comes with various methods to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. I think It’s enough about the introduction and let’s get our hands dirty. This is the skeleton of the Future interface. We will go in order create->status->get->cancel. The future can be obtained simply by submitting a task to an ExecutorService. Here, I’m creating a component and initializing an ExecutorService with available core capacity.

Continue reading...