How can i return the iterated set values which are of type string from a call method to a future object.do i need to store the iterated vales in a array and return that array or can any one help me out
Asked
Active
Viewed 8,813 times
0
-
3Please show us some (pseudo) code. – Tomasz Nurkiewicz Nov 07 '12 at 12:11
2 Answers
4
Use a Callable<List<String>>
, submit it to an executor, which will return a Future
whose get()
method will return a List<String>
.
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<List<String>> task = new Callable<List<String>>() {
public List<String> call() throws Exception {
List<String> list = new ArrayList<String>();
// populate list
return list;
}
};
Future<List<String>> future = executorService.submit(task);
// the list from above, returns once execution is complete
List<String> list = future.get();

Bohemian
- 412,405
- 93
- 575
- 722
-1
Use submit()
method of ExecutorService
which returns Future
Object.

Kumar Vivek Mitra
- 33,294
- 6
- 48
- 75