Looking into the Future
The Future
When dealing with concurrent processing, starting Java 1.5 the 'Future' looks bright.In java 1.5 it is now easier to collect results from asynchronous processes by getting the future.
Here are the objects that you are going to need to process concurrently and collect results from those concurrent processes:
//Please refer the the Java API documentation on how to properly instantiate the objects below
//This is just to give an overview on how they are used together and relate to each other.
//A ThreadPoolExecutor is basically a pool of threads that you configure that will asynchronously //perform the tasks that you provide it
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor();
//A completion service is the object that collects the results of the task that the ThreadPoolExecutor //completes. That is why when you instantiate it you need to pass it a ThreadPoolExecutor.
CompletionService
//A callable is a Task that returns a result. This is what you submit to the completion service.
Callable
completionService.submit(callableTask);
//A Future represents the result of the task that you have submitted to the completion service.
Future
Resources:
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ExecutorCompletionService.html
Comments