java定时器Timer对象

//这是一个每间隔10秒运行一次的代码,期中日期可自定义该你想改的时间到时候会自动运行,见代码:

package ThreadTest;

import java.text.*;

import java.util.*;

class LogTimerTask extends TimerTask{
	public void run(){
		System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(new Date()));

	}
}
public class ThreadTest14 {
	public static void main(String[] args) throws ParseException {
		Timer t = new Timer();
		t.schedule(new LogTimerTask(),
				new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").parse("2018-08-02 16:24:00 000"),
				10*1000);
	}
	
}

猜你喜欢

转载自blog.csdn.net/small__snail__5/article/details/81362639