//ScheduledThreadPoolExecutor每三秒执行一次 public static void main(String[] args) { ScheduledThreadPoolExecutor scheduled = new ScheduledThreadPoolExecutor(2); scheduled.scheduleAtFixedRate(new Runnable() { int i = 0; @…
可以用线程来做,每隔几秒开一个线程代码如下 public void runTask() { final long timeInterval = 120000;// 两分钟运行一次 final ThreadService threadService = new ThreadService(); Runnable runnable = new Runnable() { public void run() { while (true) { // ------- code for task to run…
现在项目中用到需要定时去检查文件是否更新的功能.timer正好用于此处. 用法很简单,new一个timer,然后写一个timertask的子类即可. 代码如下: package comz.autoupdatefile; import java.util.Timer; import java.util.TimerTask; public class M { public static void main(String[] args) { // TODO todo.generated by zoer…