쓰레드 사용하기
쓰레드 사용하기
- 쓰레드(Thread) 두 개를 만들어 실행시켜 보자
- 두 가지 쓰레드 작성법을 배운다.
- 인터페이스 Runable을 구현하거나 쓰레드 클래스를 상속한다.
public class MyRun implements Runnable{ public void run(){ show(); } public void show(){ for(int i=0;i<100;i++){ System.out.print("S"); } }} |
public class MyThread extends Thread{ public void run(){ for(int i=0;i<100;i++){ System.out.print("T"); } }} |
public class MyRunMain{ public static void main(String[] args) { MyRun mr1=new MyRun(); Thread t1=new Thread(mr1); MyThread t2=new MyThread(); t1.start(); t2.start(); for(int i=0;i<100;i++){ System.out.print("M"); } }} |
댓글
댓글 쓰기