作者darkk6 (Mr. Pan)
看板java
标题Re: 请问如何在实作runnable的类别里,睡不同的时间?
时间Thu Sep 8 17:36:08 2011
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)
1F:推 spiderman007:感谢你的回答....有帮助到我! 09/08 18:07
2F:推 terrybob:推,受教了 09/08 18:15
3F:推 gmoz:推 09/08 21:25