I have JList
using DefaultListModel
to update the strings in list in UI , returned by a class as shown
class ResponseGiver implements Callable<Future>{
int i;
//Constructor to initialize i
String call(){
...............
...............
return i;
}
and i have other class that will update the results obtained from above
class Viewer {
ExecutorService es = new Executors.newFixedThreadPool(10);
List<Future<String>> futures = new ArrayList<Future<String>>();
for(int i =0;i<10;i++)
{
futures.add(new ResponseGiver(i));
}
for(Future<String> x : futures) //loop 2nd will be called 10 times
{
String p = x.get();
//update GUI with p
}
Now the question is, suppose in loop 2nd , in the 5th loop, the get()
function takes some time say 10 seconds, and during the mean time, the other futures from 6th to 10th have their result ready.
So my screen would wait for 5th result, even 6th to 10th are ready.
I want my screen to be updated as soon as any of the 10 futures return the result.