請問如何在實作runnable的類別裡,睡不同的時間?

看板java作者 (千里之外)時間14年前 (2011/09/08 17:33), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
如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
文章代碼(AID): #1EQ8lFlq (java)
文章代碼(AID): #1EQ8lFlq (java)