import java.text.SimpleDateFormat;
import java.util.Timer;
import java.util.TimerTask;
public class MutilTimer
{
//定时器
private static Timer timer = new Timer();
private static final long confirmTime = 5*1000;
//类变量
private static MutilTimer multilTimer = new MutilTimer();
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static void main(String[] args)
{
multilTimer.init();
}
private static long wait = 3000l;
private void init()
{
long repeatedWait = wait + confirmTime;
timer.schedule(new TimerTask() {
@Override
public void run() {
exec();
}
},wait);
timer.schedule(new TimerTask() {
@Override
public void run() {
wait += 1000l;
init();
}
},repeatedWait);
}
private void exec()
{
System.out.println("hello, runTime is " + sdf.format(System.currentTimeMillis()));
}
}