File tree 2 files changed +23
-5
lines changed
src/main/java/io/concurrency/chapter01/exam01
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
5
-
5
+ /*
6
+ * 동시성 - CPU 개수 < 작업의 개수에 최적화 되어있습니다.
7
+ *
8
+ * 만약 CPU 개수보다 작업의 개수가 한개라도 많다면 동시성 처리로 진행된다.
9
+ * */
6
10
public class ConcurrencyExample {
7
11
public static void main (String [] args ) {
8
-
12
+ System .out .println ("CPU 개수 : " +Runtime .getRuntime ().availableProcessors ());
13
+ // CPU 개수 * 2
9
14
// int cpuCores = Runtime.getRuntime().availableProcessors() * 2;
15
+
16
+ // CPU 개수 + 1
10
17
int cpuCores = 13 ;
11
18
12
19
// CPU 개수를 초과하는 데이터를 생성
Original file line number Diff line number Diff line change 2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
5
-
5
+ /*
6
+ * 병렬성 - CPU 개수 >= 작업의 개수에 최적화 되어있습니다.
7
+ * */
6
8
public class ParallelismExample {
7
9
public static void main (String [] args ) {
8
- // int cpuCores = 1;
10
+ System .out .println ("CPU 개수 : " +Runtime .getRuntime ().availableProcessors ());
11
+
9
12
int cpuCores = Runtime .getRuntime ().availableProcessors ();
10
13
11
14
// CPU 개수만큼 데이터를 생성
@@ -16,7 +19,15 @@ public static void main(String[] args) {
16
19
17
20
// CPU 개수만큼 데이터를 병렬로 처리
18
21
long startTime1 = System .currentTimeMillis ();
19
- long sum1 = data .parallelStream ()
22
+
23
+ /*
24
+ * 병렬스트림 진행 (CPU를 전부 사용해서 각각 작업을 하나씩 물기)
25
+ * */
26
+ // long sum1 = data.parallelStream()
27
+ /*
28
+ * 일반스트림 진행 (CPU를 하나만 사용해서 작업을 진행)
29
+ * */
30
+ long sum1 = data .stream ()
20
31
.mapToLong (i -> {
21
32
try {
22
33
Thread .sleep (500 );
You can’t perform that action at this time.
0 commit comments