-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadExam02.java
More file actions
53 lines (44 loc) · 1022 Bytes
/
ThreadExam02.java
File metadata and controls
53 lines (44 loc) · 1022 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
41
42
43
44
45
46
47
48
49
50
51
52
53
package thread;
class AlphaThread2 implements Runnable{
@Override
public void run(){
for ( char c = 'A' ; c <= 'Z'; c++) {
System.out.println(c);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class DigitThread2 implements Runnable{
@Override
public void run() {
for ( int i = 1; i <= 100 ; i ++ ) {
System.out.print(i);
if ( i % 10 == 0 ) {
System.out.println();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public class ThreadExam02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
AlphaThread2 obj = new AlphaThread2();
DigitThread2 obj2 = new DigitThread2();
// 2. 생성한 Runnable 객체를 이용해서 Thread 객체를 생성
Thread t1 = new Thread(obj,"t1");
Thread t2 = new Thread(obj2,"t2");
t1.start();
t2.start();
}
}