請問如何在實作runnable的類別裡,睡不同的時間?
如code
class Test implements Runnable{
public void run(){
try{
Thread.sleep(1000);
}
catch(InterruptedException e){}
.......sleep(2000)??
}
}
public class ThreadEx{
public static void main(String[] args){
Test ta = new Test();
Thread t1 = new Thread(ta);
t1.start();
}
}
請問該怎麼改,才能新增一個Thread 物件 t2 停2秒呢??
但原本的t1仍在...是要另增一個類別去實作runnable嗎??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.46.115.213
討論串 (同標題文章)