Kevin Bear wrote:...
Two questions:
1. Will the order of the results in the list be guaranteed? (From what I read, it seems not. But the experiments I have done always produce nicely ordered results)
2. if I use the following code to examine the result after the for loops, will the get() method ensure that all the calculations in the for loops completed before the result is examined?
1. In your example you are putting the Futures in the List. The Future is returned immediately when the exec.submit() is called. It does not wait for the callable to finish. This means that the Futures
are ordered. When you read the code, you are waiting for the callable to finish using the get() method so if the Object you want isn't ready you wait for it to be ready - so they are retrieved in order as well. Because you are storing the Future in the List you are guaranteed they will be in order.
2. Yes, as per the API, get will wait for the callable to complete before returning.
Kevin Bear wrote:
An addtional question: I have an ArrayList of Objects (I'll name it callableList) for use in the Callable module. callableList gets some new items (as well as get some items removed) every time the program enters the innnermost for loop. It seems that this would cause concurrency problem,
Perhaps, perhaps not. You don't show what happens with callableList in the code you provide, and we have no clue what the Callable code is doing, so it is impossible to say with the code you provided.