Thread


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :Sung 2000년 2월 09일 02:16:56

In Reply to: 소스 부탁드립니다. posted by 야키 on 2000년 2월 08일 15:39:52:

Your base class should extend Thread.


Start the thread by "new YourClass().start()".


In the run() method in YourClass,


===========================================
public void run() {
//sleep for 5 seconds and wake up
while(true){
try{
sleep(5000);

System.out.println("Woke up");
stop();
//do something
}
catch(IllegalThreadStateException itx){
}
catch(InterruptedException itx){
}
}
}
==============================================
-Or-
If you want to create a selfish method to wait then,


public void pause(int delay) {
long s = System.currentTimeMillis();
long sleepTime = delay * 1000;

while(System.currentTimeMillis() < (s + sleepTime));
//do something.
}


다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]