private static void timerTask() throws InterruptedException { Timer timer = new Timer();
TimerTask timerTask = new TimerTask() { @Override public void run() { System.out.println("hi, 欢迎关注:java技术栈"); } };
long delay = 2000;
long period = 3 * 1000;
timer.schedule(timerTask, delay, period);
Thread.sleep(20000);
timer.cancel(); timer.purge(); }
|