Reputation: 105210
I have a collection of objects, which I want to map to another collection, doing similar routine operations for every element. I'd like to do these atomic routine operations in parallel threads and looking for some ready-to-use library that can help me:
Collection<X> source = // ...
Collection<Y> result = Threader.map(
source,
new Mapping<X, Y>() {
@Override
public Y map(X src) {
// do something and return an instance of Y
}
}
);
I understand that it's easy to implement but I don't want to re-invent the wheel. Do you know any libraries that contain such a Threader
class?
I think that Java 8 streams are going to do something similar to this...
I submitted a feature request to Guava: https://code.google.com/p/guava-libraries/issues/detail?id=1422
Upvotes: 2
Views: 118
Reputation: 12224
The functionaljava library may do what you want. It provides its own collection types that you can convert to/from java.util.Collection. The collection types have map operations for which you can provide your own functions, and a concurrency stategy for that mapping. There's a good blog posting on using functionaljava for parallel list processing here:
http://apocalisp.wordpress.com/2008/06/30/parallel-list-transformations/
Upvotes: 2