-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainThread.java
More file actions
40 lines (33 loc) · 956 Bytes
/
Copy pathMainThread.java
File metadata and controls
40 lines (33 loc) · 956 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
33
34
35
36
37
38
39
40
package com.javaex.thread.ex03;
public class MainThread {
public static void main(String[] args) {
// 쓰레드를 불러와 실행
// Thread thread = new DigitThread();
Thread thread = new Thread(new DigitThread());
// 쓰레드의 시작
thread.start();
// 메인 쓰레드의 코드를 만들겠습니다.
/* - > AlphabetThread로 이동
for (char ch = 'A'; ch <= 'Z'; ch++) {
System.out.println(ch);
// 출력 속도 지연
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
*/
// Thread thread2 = new AlphabetThread();
Thread thread2 = new Thread(new AlphabetThread());
thread2.start();
// thread와 thread2를 메인 쓰레드의 흐름에 합류
try {
thread.join();
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("메인쓰레드 종료");
}
}