import java.util.Timer; import java.util.TimerTask; public class Demo2 { //执行时间,时间单位为毫秒,读者可自行设定,不得小于等于0 private static Integer period = 5000; //延迟时间,时间单位为毫秒,读者可自行设定,不得小于等于0 private static Integer delay = 1; public static void main(String[] args) { Timer timer = new Timer(); timer.schedule(new TimerTask(){ @Override public void run() { System.out.println("qqq"); } }, delay, period); } }