timer demo 之一

关于定时器的简单例子

Timer_demo.java

public class Timer_demo {
private Timer_demo demo = null;
private final Timer timer = new Timer();

private int minutes;

public Timer_demo(int minutes) {
this.minutes = minutes;
}
public void setObject(Timer_demo demo )
{
this.demo = demo;
}

public void start() {
timer.schedule(new TimerTask() {

public void run() {
playSound();
//demo.minutes+=1;
demo.start();

}

private void playSound()
{
System.out.println("Your egg is ready!"+new Date().toString());
}

}, minutes * 10 * 1000);
}

/**
* @param args
*/
public static void main(String[] args)
{
Timer_demo demo = new Timer_demo(1);
demo.setObject(demo);
demo.start();

}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页