Java java.util.Timer is a utility class that can be used to schedule a thread to be executed at certain time in future. Java Timer class can be used to schedule a task to be run one-time or to be run at regular intervals. Java TimerTask java.util.Tim…
import java.util.Timer; import java.util.TimerTask; public class Timer { .... public void schedule(TimerTask task, long delay) { .... } .... } public abstract class TimerTask implements Runnable { ... } 1. 使用匿名内部类 new Timer().schedule(new TimeTask(){…
1. 建立timer import java.util.Timer; import java.util.TimerTask; public class Start { public class Start { private static final int RT_TIME_INTERVAL = 30*1000; //30s public static void main(String[] args) { TimerTask task = new MyTask(); Timer timer =…