日期:2014-05-20 浏览次数:20844 次
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");