-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForkJoinMain1.java
More file actions
32 lines (24 loc) · 859 Bytes
/
Copy pathForkJoinMain1.java
File metadata and controls
32 lines (24 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package parallel.forkjoin;
import util.MyLogger;
import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.IntStream;
import static util.MyLogger.*;
public class ForkJoinMain1 {
public static void main(String[] args) {
List<Integer> data = IntStream.rangeClosed(1,8)
.boxed()
.toList();
log("[생성] " + data);
// ForkJoinPool 생성 및 작업 수행
ForkJoinPool pool = new ForkJoinPool(2);
long start = System.currentTimeMillis();
SumTask task = new SumTask(data);
// 병렬로 합을 구한 후 결과 출력
int result = pool.invoke(task);
pool.shutdown();
long end = System.currentTimeMillis();
log("time: " + (end - start) + "ms, sum : " + result);
log("pool : " + pool);
}
}