I'm looking for a class where I can override a method to do the work, and return the results like an iterator. Something like this:
ParallelWorkIterator<Result> itr = new ParallelWorkIterator<Result>(trials,threads) {
public Result work() {
//do work here for a single trial...
return answer;
}
};
while (itr.hasNext()) {
Result result = itr.next();
//process result...
}
This is mainly going to be used for things like monte carlo simulations, but I don't want to have to deal with setting up thread pools and managing returning threads every time. I rolled my own class that hopefully accomplishes this, but I'm not confident enough in it and thought I'd check if something like this already existed.
Edit: To be clear, I want it to keep running in the background and queuing results after each work method returns until all trials have been completed. So the next method may wait to return until there is a result in the queue.