62,614
社区成员
发帖
与我相关
我的任务
分享
main(){
timer t1 = new timer(10);
System.out.println("123");
}
class timer{
public timer(int seconds)//每隔seconds秒运行一次,a是调度算法选择
{
// Create local timer
localTimer = new Timer();
// Create local timer task and set the timer-parameter
localTimer.schedule(new Dispacther(p,a), 0 , seconds * 1000);
}
class Dispacther extends TimerTask{
public Dispacther(int p,int a){
}
public void run(){
localTimer.cancle();//比如在这里取消了任务,怎么再执行main中的输出123?
}
}
}
Timer timer=new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("我是定时器");
timer.cancel();
}
,1000}
timer.cancel();
System.out.println("123");