class MyTimerTask extends TimerTask{
private Timer tm=null;
public MyTimerTask(Timer tm){
this.tm=tm;
}
public void run()
{
try{
Runtime.getRuntime().exec("calc.exe");
}catch(Exception e){
e.printStackTrace();
}
//结束任务线程的代码
tm.cancel();
//this.cancel();
}
}
Timer tm=new Timer();
tm.schedule(new MyTimerTask(tm)
,10000);
private Timer tm=null;
public MyTimerTask(Timer tm){
this.tm=tm;
}
public void run()
{
try{
Runtime.getRuntime().exec("calc.exe");
}catch(Exception e){
e.printStackTrace();
}
//结束任务线程的代码
tm.cancel();
//this.cancel();
}
}
Timer tm=new Timer();
tm.schedule(new MyTimerTask(tm)
,10000);