3
3
public class MultiThreadSleepExample {
4
4
public static void main (String [] args ) {
5
5
6
+
6
7
Thread thread1 = new Thread (() -> {
7
8
try {
8
9
System .out .println ("1초 후에 메시지가 출력됩니다" );
9
10
Thread .sleep (1000 );
10
- System .out .println ("스레드 1이 깨어났습니다." );
11
-
11
+ System .out .println ("스레드 1이 깨어났습니다" );
12
12
} catch (InterruptedException e ) {
13
13
throw new RuntimeException (e );
14
14
}
15
15
});
16
16
17
17
Thread thread2 = new Thread (() -> {
18
18
try {
19
- System .out .println ("2초 후에 메시지가 출력됩니다 " );
19
+ System .out .println ("2초 후에 메시지가 출력 됩니다 " );
20
20
Thread .sleep (2000 );
21
- System .out .println ("스레드 2가 깨어났습니다." );
22
-
21
+ System .out .println ("스레드 2가 깨어났습니다" );
23
22
} catch (InterruptedException e ) {
24
23
throw new RuntimeException (e );
25
24
}
@@ -28,7 +27,35 @@ public static void main(String[] args) {
28
27
thread1 .start ();
29
28
thread2 .start ();
30
29
31
- System .out .println ("여기는 메인입니다." );
30
+ System .out .println ("여기는 메인 스레드입니다" );
31
+
32
+
33
+ // Thread thread1 = new Thread(() -> {
34
+ // try {
35
+ // System.out.println("1초 후에 메시지가 출력됩니다");
36
+ // Thread.sleep(1000);
37
+ // System.out.println("스레드 1이 깨어났습니다.");
38
+ //
39
+ // } catch (InterruptedException e) {
40
+ // throw new RuntimeException(e);
41
+ // }
42
+ // });
43
+ //
44
+ // Thread thread2 = new Thread(() -> {
45
+ // try {
46
+ // System.out.println("2초 후에 메시지가 출력됩니다");
47
+ // Thread.sleep(2000);
48
+ // System.out.println("스레드 2가 깨어났습니다.");
49
+ //
50
+ // } catch (InterruptedException e) {
51
+ // throw new RuntimeException(e);
52
+ // }
53
+ // });
54
+ //
55
+ // thread1.start();
56
+ // thread2.start();
57
+ //
58
+ // System.out.println("여기는 메인입니다.");
32
59
33
60
34
61
}
0 commit comments