JAVA Basic 강의자료] NotRunnable

 

JAVA Basic 강의자료] NotRunnable

 

 

실무개발자를위한 실무교육 전문교육센터학원
www.oraclejava.co.kr에 오시면 보다 다양한 강좌를 보실 수 있습니다.

 

 

 

NotRunnable

 

 

*대기와 복구 시키기
  -sleep(long millis) 사용
     :원하는 대기 시간을 1/1000초 단위로 삽입
     :설정 시간 경과 후 자동 복귀
  -Object클래스의 wait()와 notify() 사용
     :wait()로 대기 시키고, notify()로 복귀 시킴
 

 

<소스코드>

 

import java.util.*;
class NotRunnableThread extends Thread {//스레드상속
 private int number = 0;
 public NotRunnableThread(int n) {
    System.out.println(this.getName()+":스레드시작");
      number = n;
   }
   public void run() {
      int i = 0;
    while(i < number) {
        System.out.println(this.getName() +":"+i + new Date().toString() + "\t");
            try{
          this.sleep(2000);
             }catch(Exception e){System.out.println(e);}
            i++;   
  }
     System.out.println(":스레드종료");
   }
}
public class NotRunnableThreadMain {
   public static void main(String args[] ) {
      NotRunnableThread s = new NotRunnableThread(5);
      s.start();
   }
}

+ Recent posts