首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java固定时间间隔实施

2012-12-20 
Java固定时间间隔执行package com.lbx.emailimport java.util.Timerimport java.util.TimerTaskpublic

Java固定时间间隔执行

package com.lbx.email;import java.util.Timer;import java.util.TimerTask;public class Test2 {private final Timer timer = new Timer();private final int minutes;public Test2(int minutes) {this.minutes = minutes;}public void start() {timer.schedule(new TimerTask() {public void run() {playSound();timer.cancel();Test2 eggTimer = new Test2(2);eggTimer.start();}private void playSound() {System.out.println("Your egg is ready!");// Start a new thread to play a sound...}}, minutes * 1 * 1000);}public static void main(String[] args) {Test2 eggTimer = new Test2(1);eggTimer.start();}}

?

热点排行