package com.shanhw.practice;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
class Bombing extends TimerTask {
@Override
public void run() {
System.out.println("bombing!");
}
}
public class TestTraditionalTimer {
public static void timer() {
Timer time = new Timer();
Bombing b = new Bombing();
// 10秒钟后爆炸
// time.schedule(b, 10000);
// 15秒钟后爆炸,以后每两秒爆炸一次
time.schedule(b, 5000, 2000);
while (true) {
System.out.println(Calendar.getInstance().get(Calendar.SECOND));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
timer();
}
}
Timer
最新推荐文章于 2022-06-30 14:52:23 发布