Timer

来源:互联网 发布:跟美团众包类似软件 编辑:程序博客网 时间:2024/06/06 19:13
package com.shanhw.practice;import java.util.Calendar;import java.util.Timer;import java.util.TimerTask;class Bombing extends TimerTask {@Overridepublic void run() {System.out.println("bombing!");}}public class TestTraditionalTimer {public static void timer() {Timer time = new Timer();Bombing b = new Bombing();// 10秒钟后爆炸// time.schedule(b, 10000);// 15秒钟后爆炸,以后每两秒爆炸一次time.schedule(b, 5000, 2000);while (true) {System.out.println(Calendar.getInstance().get(Calendar.SECOND));try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}public static void main(String[] args) {timer();}}

原创粉丝点击