Contenu connexe
Similaire à Fork/Join Framework。そしてLambdaへ。
Similaire à Fork/Join Framework。そしてLambdaへ。 (20)
Plus de Yuichi Sakuraba (20)
Fork/Join Framework。そしてLambdaへ。
- 3. 1994 Java 1.0α Thread
Runnable
2004 J2SE 5.0 JSR 166
Concurrency Utilities
- 4. 1994 Java 1.0α Thread
Concurrent Runnable
2004 J2SE 5.0 JSR 166
Concurrency Utilities
Parallel
- 12. 分割統治法
フィボナッチ数列 F0 = 0, F1 = 1
Fn = Fn-1+ Fn-2
public int compute(int n) {
if (n <= 1) {
return n;
}
return compute(n-1) + compute(n-2);
}
- 13. 分割統治法
フィボナッチ数列 F0 = 0, F1 = 1
Fn = Fn-1+ Fn-2
class FibonacciTask extends RecursiveTask<Integer> {
private final int n;
FibonacciTask(int n) { this.n = n; }
protected Integer compute() {
if (n <= 1) { return n; }
FibonacciTask f1 = new FibonacciTask(n - 1);
f1.fork();
FibonacciTask f2 = new FibonacciTask(n - 2);
return f2.compute() + f1.join();
}
}
- 14. Work Stealing
Task
両端キュー Deque
Worker1
Comp Fork
Comp Fork
Worker2 Comp Fork
Comp Fork
ソート 検索
数値計算
行列操作
枝狩り et al.
- 15. 内部イテレータ
Java
List<Integer> numbers = ...;
for (int i = 0; i < numbers.size(); i++) {
numbers.set(i, numbers.get(i) * 2);
}
Groovy
def numbers = ...
独立
numbers.collect { it * 2 } 並行処理可
- 16. extra166y ParallelArray
Integer[] numbers = ...;
ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array
= ParallelArray.createFromCopy(numbers, pool);
Ops.Op<Integer, Integer> doubler = new Ops.Op<>() {
@Override
public Integer op(Integer x) {
return x * 2;
}
};
array.withMapping(doubler);
- 17. extra166y ParallelArray
Integer[] numbers = ...;
ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array
= ParallelArray.createFromCopy(numbers, pool);
Ops.Op<Integer, Integer> doubler = new Ops.Op<>() {
@Override
public Integer op(Integer x) {
return x * 2;
}
};
array.withMapping(doubler);
- 18. extra166y ParallelArray
Integer[] numbers = ...;
ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array
= ParallelArray.createFromCopy(numbers, pool);
Ops.Op<Integer, Integer> doubler
= #{Integer num -> num * 2};
array.withMapping(doubler); ラムダ式
Project Lambda
- 19. extra166y ParallelArray
Integer[] numbers = ...;
ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array
= ParallelArray.createFromCopy(numbers, pool);
Ops.Op<Integer, Integer> doubler
= #{Integer num -> num * 2};
array.withMapping(doubler); ラムダ式
Project Lambda
- 20. extra166y ParallelArray
Integer[] numbers = ...;
ForkJoinPool pool = new ForkJoinPool();
ParallelArray<Integer> array
= ParallelArray.createFromCopy(numbers, pool);
array.withMapping(#{Integer num -> num * 2});
- 21. Multicore Era
Thread/Executor
JSR 166y
Fork/Join Framework
Work Stealing
extra166y
内部イテレータ
JSR 335 もっと簡単に!
Project Lambda
- 22. Tips
時間のかかる処理はしない
キャッシュを考慮する
参考 ITpro Java SE 7 徹底理解
No.2 細粒度の並行処理 - Fork/Join Framework
No.3 Fork/Join Framework から Project Lambda へ