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

看板java作者 (Mr. Pan)時間12年前 (2011/09/08 17:36), 編輯推噓3(300)
留言3則, 3人參與, 最新討論串2/2 (看更多)
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
文章代碼(AID): #1EQ8oBnw (java)
文章代碼(AID): #1EQ8oBnw (java)