用定时器来做
class Trd implements Runnable{
public void run(){
//do something
}
}
class Main{
Main(){
final Thread t=new Thread(new Trd());
t.run();
final Timer timer=new Timer();
timer.schedule(new TimerTask(){
public void run(){
t.interrupt();
this.cancel();
timer.cancel();
}
}, 5000);
}
} |