37. Then comes the Parallel Arrays API
http://g.oswego.edu/dl/concurrency-interest/
38. Then comes the Parallel Arrays API
ForkJoinPool pool = new ForkJoinPool() ; // package !
ParralelLongArray a = ParralelLongArray.create(pool) ;
39. Then comes the Parallel Arrays API
Ops.LongOp add2 = new Ops.LongOp() {
@Override
public long op(long l1) {
return l1 + 2 ;
}
} ;
a2 = a.withMapping(add2) ;
40. Then comes the Parallel Arrays API
Ops.LongPredicate filter = new Ops.LongPredicate() {
@Override
public boolean op(long l1) {
return l1 > 50 ;
}
}
a2 = a.withFilter(filter) ;
a2.all() ;
41. Then comes the Parallel Arrays API
Ops.LongReducer reducer = new Ops.LongReducer() {
@Override
public long op(long l1, long l2) {
return l1 + l2 ;
}
}
long reducedValue = a.reduce(reducer, 0L) ;
43. And then comes the JDK 8
Collection<Person> persons = ... ;
int maxAge = persons.stream().map(p -> p.getAge()).reduce(0, Math::max) ;
Collection<Person> oldies = new ArrayList<>() ;
persons.stream().filter(p -> p.age > 40).into(oldies) ;
44. And then comes the JDK 8
Collection<Person> persons = ... ;
int maxAge = persons.stream().parallel()
.map(p -> p.getAge()).reduce(0, Math::max) ;
Collection<Person> oldies = new ArrayList<>() ;
persons.stream().parallel().filter(p -> p.age > 40).into(oldies) ;
45. And then comes the JDK 8
public interface Spliterator<E> {
public Spliterator<E>[] splits() ;
public int getNaturalSplits() ;
}
http://www.parleys.com/#st=5&id=3125&sl=0
51. 2nd caveat : performance
long begin = System.nanoTime() ;
List<String> hugeList = new ArrayList<>(N) ; // N = 16_000_000
for (int i = 0 ; i < N ; i++) {
long l = random.nextLong() ;
l = l > 0 ? l : -l ;
hugeList.add(Long.toString(l, 32)) ;
}