文章目录
在应用开发中,需要一些周期性的操作,比如每3分钟执行某一些操作等。比较简单的是使用java.util.Timer 工具类。
1. 10秒倒数器
private static int count = 10;
public static void practice12() throws Exception {
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
System.out.println(count--);
if (count <= 0) {
timer.cancel();
}
} // end run
}, 0, 1000); // 1000ms,间隔
}
public static void main(String[] args) {
try {
practice12();
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
10
9
8
7
6
5
4
3
2
1

664

被折叠的 条评论
为什么被折叠?



