class Echo extends Thread{
private Thread t;
Echo(String word){
super(word);
}
public void setNextThread(Thread t){
this.t=t;
}
public void run(){
for(int i=0; i<10; i++){
try{sleep(3000);}catch(InterruptedException e){}
System.out.print("Thread"+getName()+">"+i+"\t");
t.interrupt();
}
}
public static void main(String[] args){
Echo e1 = new Echo("일");
Echo e2 = new Echo("이");
Echo e3 = new Echo("삼");
e1.setNextThread(e2);
e2.setNextThread(e3);
e3.setNextThread(e1);
e1.start(); e2.start(); e3.start();
e1.interrupt();
}
}
'개발하자 > JAVA고급' 카테고리의 다른 글
Thread.yield(); (0) | 2015.04.02 |
---|---|
쓰레드 안전하게 종료시키는 방법 (0) | 2015.04.02 |
Thread,InterruptedException,join(); (0) | 2015.03.31 |
파일보내기/파일크기보내기 (0) | 2015.03.19 |
웹사이트소스불러오기 (0) | 2015.02.18 |