-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadStopMainV2.java
More file actions
39 lines (31 loc) · 1.13 KB
/
Copy pathThreadStopMainV2.java
File metadata and controls
39 lines (31 loc) · 1.13 KB
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
package thread.control.interrupt;
import util.MyLogger;
import static util.ThreadUtils.sleep;
public class ThreadStopMainV2 {
public static void main(String[] args) {
MyTask work = new MyTask();
Thread thread = new Thread(work, "work");
thread.start();
sleep(4000);
MyLogger.log("작업 중지 요청 Interrupt");
thread.interrupt();
MyLogger.log("인터럽트 상태 " + thread.isInterrupted());
}
static class MyTask implements Runnable {
@Override
public void run() {
try {
while(true) {
MyLogger.log("작업 중");
Thread.sleep(3000);
}
} catch (InterruptedException e) {
MyLogger.log("work 스레드 인터럽트 상태 = " + Thread.currentThread().isInterrupted() );
MyLogger.log("interrupt Message() = " + e.getMessage());
MyLogger.log("Thread State() = " + Thread.currentThread().getState());
}
MyLogger.log("자원 정리");
MyLogger.log("자원 종료");
}
}
}