Very simple & lightweight util class for Java to assist the creation of concurrent tasks and loop parallelization. You can use this library to process collections in parallel just using very few lines. If you need something more powerful, I recommend you to check the functionaljava project which provides high-order concurrency abstractions http://code.google.com/p/functionaljava/.
Transform a set of words to upper case in parallel:
Collection<String> upperCaseWords =
Parallel.ForEach(words, new Parallel.F<String, String>() {
public String apply(String s) {
return s.toUpperCase();
}
});
Transform a set of words to upper case but using no more than 4 threads:
Collection<String> upperCaseWords =
new Parallel.ForEach<String, String>(words)
.withFixedThreads(4)
.apply(new Parallel.F<String, String>() {
public String apply(String s) {
return s.toUpperCase();
}
}).values();
If you use Maven, just paste the following snippet into your pom.xml:
<dependency>
<groupId>es.usc.citius.common</groupId>
<artifactId>parallel-loops</artifactId>
<version>1.0</version>
</dependency>