import java.util.TimerTask;
public class MyTask extends TimerTask{
@Override
public void run() {
System.out.println("boombing");
}
}
//****************************
package com.ygl;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TraditionTimerTest {
public static void main(String[] args) {
Timer timer=new Timer();
TimerTask myTask=new MyTask();
timer.schedule(myTask, 10000,3000);//第一次10s后触发,以后每隔3秒触发
while(true){
System.out.println(new Date().getSeconds());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
//***********************************
32
34
35
36
37
38
39
40
41
42
boombing
43
44
45
boombing
46
47
48
boombing
49
50
51
boombing