Skip to content

Commit 9d7da5d

Browse files
committed
20241219 CPU , IO bound 학습
1 parent a86d2f5 commit 9d7da5d

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
import java.util.concurrent.ExecutorService;
77
import java.util.concurrent.Executors;
88
import java.util.concurrent.Future;
9-
9+
/*
10+
* CPU Bound - 영상처리, AI 작업 관련
11+
*
12+
* 멀티코어의 병렬성을 이용한다.
13+
*
14+
* CPU 수 >= 스레드 개수
15+
* */
1016
public class CPUBoundExample {
1117
public static void main(String[] args) throws InterruptedException {
1218

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
import java.nio.file.Path;
66
import java.util.concurrent.ExecutorService;
77
import java.util.concurrent.Executors;
8-
8+
/*
9+
* IO Bound - DB작업이나 파일 읽는 작업
10+
*
11+
* 멀티스레드의 동시성을 이용한다.
12+
*
13+
* CPU 수 < 스레드 개수
14+
* */
915
public class IOBoundExample {
1016
public static void main(String[] args) {
11-
int numThreads = Runtime.getRuntime().availableProcessors() / 2;
17+
int numThreads = Runtime.getRuntime().availableProcessors() * 2;
1218
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
1319

1420
for (int i = 0; i < numThreads; i++) {
@@ -17,7 +23,7 @@ public static void main(String[] args) {
1723

1824
// IO 가 집중 되는 작업
1925
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"));
26+
Files.readAllLines(Path.of("C:\\workspace\\java-concurrency-study\\src\\main\\java\\io\\concurrency\\chapter01\\exam03\\sample.txt"));
2127
System.out.println("스레드: " + Thread.currentThread().getName() +", " +j); // IO Bound 일때 ContextSwitching 이 일어난다
2228
}
2329

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
why so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happywhy so happy

0 commit comments

Comments
 (0)