Re: 請問如何在實作runnable的類別裡,睡不同的時間?
like this ?
class Test implements Runnable{
private int time;
public Test(int time){
this.time=time;
}
public void run(){
try{
Thread.sleep(time);
}
catch(InterruptedException e){}
/* 一些判斷,不然一直執行會有生不完的 Thread */
new Thread(new Test(2000)).start();
}
}
public class ThreadEx{
public static void main(String[] args){
Test ta = new Test(1000);
Thread t1 = new Thread(ta);
t1.start();
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.39.75
※ 編輯: darkk6 來自: 140.116.39.75 (09/08 17:37)
推
09/08 18:07, , 1F
09/08 18:07, 1F
推
09/08 18:15, , 2F
09/08 18:15, 2F
推
09/08 21:25, , 3F
09/08 21:25, 3F
討論串 (同標題文章)