- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter57.java
More file actions
Latest commit
49 lines (35 loc) · 1.55 KB
/
Copy pathChapter57.java
File metadata and controls
49 lines (35 loc) · 1.55 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
40
41
42
43
44
45
46
47
48
49
packagechapter57;
//첫번재 스레드 : Thread 클래스를 상속 받아서 run()메서드 오버라이드 시켜서 사용
classOne1extendsThread{
@Override
publicvoidrun() {
for(inti = 0;i<300;i++) {
System.out.print("$");
}
}
}
//두분째 스레드 : Runnable 인터페이스를 구현한 클래스를 사용
//-> run()메서들 오버라이드 시켜서 사용
classTwo1implementsRunnable{
@Override
publicvoidrun() {
for(inti = 0;i<300;i++) {
System.out.print("*");
}
}
}
publicclassThreadEx3 {
publicstaticvoidmain(String[] args) {
//멀티 스레드 : cpu가 수행할 여러개의 작업 단위의 코드 블럭을 작성(run() 메서드의 내용)
//Thread 클래스릏 상속 받아서 작성한 단위를 수행 시키기
One1th = newOne1();//Thread 클래스의 멤버들을 사용할 수 있다
th.start();//run() 메서드내에서 오버라이드 되어서 수행해야 코드를 수행시킨다
//Runnable 인터페이스로 구현한 작업 단위의 코드 블록을 작성 (run() 메서드의 내용)
//인터페이스 변수명 = 구현 클래스
//-> Runnable 인터페이스를 구현한 클래스(Two1)의 객체를 Thread 클래스의 생성자의 매게 변수 인수로 넣어서 수행
Runnableth1 = newTwo1();
Threadt = newThread(th1);
t.start();
System.out.println("Main Thread 종료!!!");
}
}