package com.lee2;
public class Test2 {
public static void main(String[] args) {
Alba alba1=new Alba("어서오세요");
Alba alba2=new Alba("주문은?");
Alba alba3=new Alba("또오세요");
alba1.run();
alba2.run();
alba3.run();
System.out.println("============");
alba1.start(); //10분
alba2.start(); //10분
alba3.start(); //20분
//run() - run메서드 전부 실행
//start() - background에서 실행
//순서가 random
}
}
package com.lee2;
public class Alba extends Thread{
String msg;
public Alba(String msg){
this.msg=msg;
}
@Override
public void run() {
for( int i=0 ; i<10 ; i++){
System.out.println(msg);
try {
Thread.sleep(1000);//1000->1초
} catch (Exception e) {
System.out.println("스레드 에러 발생");
System.out.println(e.getMessage());
}
}
System.out.println("사장님 안녕히계세요");
}
}