Skip to content

Commit fd6d1b0

Browse files
committed
study
1 parent 4c90609 commit fd6d1b0

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed

src/main/java/io/concurrency/chapter01/exam01/ConcurrencyExample.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
public class ConcurrencyExample {
77
public static void main(String[] args) {
88

9-
int cpuCores = Runtime.getRuntime().availableProcessors() * 2;
10-
// int cpuCores = 13;
9+
// int cpuCores = Runtime.getRuntime().availableProcessors() * 2;
10+
int cpuCores = 30;
1111

1212
// CPU 개수를 초과하는 데이터를 생성
1313
List<Integer> data = new ArrayList<>();
@@ -20,6 +20,7 @@ public static void main(String[] args) {
2020
long sum2 = data.parallelStream()
2121
.mapToLong(i -> {
2222
try {
23+
System.out.println("Thread: " + Thread.currentThread().getName() + " " + i);
2324
Thread.sleep(500);
2425
} catch (InterruptedException e) {
2526
throw new RuntimeException(e);

src/main/java/io/concurrency/chapter01/exam03/CPUBoundExample.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public static void main(String[] args) throws InterruptedException {
3636
});
3737
futures.add(future);
3838
}
39-
futures.forEach(f -> {
40-
try {
41-
f.get();
42-
} catch (InterruptedException e) {
43-
throw new RuntimeException(e);
44-
} catch (ExecutionException e) {
45-
throw new RuntimeException(e);
46-
}
47-
});
39+
// futures.forEach(f -> {
40+
// try {
41+
// f.get();
42+
// } catch (InterruptedException e) {
43+
// throw new RuntimeException(e);
44+
// } catch (ExecutionException e) {
45+
// throw new RuntimeException(e);
46+
// }
47+
// });
4848
long endTime2 = System.currentTimeMillis();
4949
System.out.println("CPU 개수를 초과하는 데이터를 병렬로 처리하는 데 걸린 시간: " + (endTime2 - startTime2) + "ms");
5050
executorService.shutdown();

src/main/java/io/concurrency/chapter01/exam03/IOBoundExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void main(String[] args) {
1717

1818
// IO 가 집중 되는 작업
1919
for (int j = 0; j < 5; j++) {
20-
Files.readAllLines(Path.of("D:\\lecture\\Java-Concurrency-Programming\\Java-Concurrency-Programming\\src\\chapter01\\exam03\\sample.txt"));
20+
Files.readAllLines(Path.of("/Users/youngjun/study/Java-Concurrency-Programming/src/main/java/io/concurrency/chapter01/exam03/sample.txt"));
2121
System.out.println("스레드: " + Thread.currentThread().getName() +", " +j); // IO Bound 일때 ContextSwitching 이 일어난다
2222
}
2323

src/main/java/io/concurrency/chapter02/exam02/MultiThreadAppTerminatedExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class MultiThreadAppTerminatedExample {
44
public static void main(String[] args) {
55

66
for (int i = 0; i < 3; i++) {
7-
Thread thread = new Thread(new ThreadStackExample.MyRunnable(i));
7+
Thread thread = new Thread(new MyRunnable(i));
88
thread.start();
99
}
1010

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.concurrency.chapter02.exam03;
2+
3+
public class StatusTest {
4+
public static void main(String[] args) {
5+
Thread thread = new Thread(() -> System.out.println("hahaha"));
6+
System.out.println(thread.getState());
7+
}
8+
}

src/main/java/io/concurrency/chapter03/exam01/BasicSleepExample.java

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static void main(String[] args) {
88
System.out.println("Hello World");
99

1010
} catch (InterruptedException e) {
11+
System.out.println("Interrupted");
1112
throw new RuntimeException(e);
1213
}
1314
}

src/main/java/io/concurrency/chapter03/exam01/InterruptSleepExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void main(String[] args) throws InterruptedException {
1818

1919
sleepingThread.start();
2020

21-
Thread.sleep(1000);
21+
Thread.sleep(3000);
2222
//
2323
sleepingThread.interrupt();
2424
}

0 commit comments

Comments
 (0)