2019-04-1218:03:32
package 多线程.定时器Timer_重要; import java.util.Timer; import java.util.TimerTask; public class TimerDemo { public static void main(String[] args) { Timer timer = new Timer(); mytimeer mytime = new mytimeer(timer); timer.schedule(mytime, 1000, 1000); } } class mytimeer extends TimerTask { Timer timer; int a = 60; public mytimeer(Timer timer) { this.timer = timer; } @Override public void run() { System.out.println("爆炸倒计时" + a--); if (a == 0) { System.out.println("boom-----"); timer.cancel();//关闭 } } }