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:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]