java簡單定時任務器
阿新 • • 發佈:2019-02-04
package com.born.yjf.test;
import java.util.Timer;
import java.util.TimerTask;
public class MyTimeTaskTest {
Timer timer;
public MyTimeTaskTest(int seconds)
{
timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);
}
class RemindTask extends TimerTask {
public void run() {
System.out.println("Time's up!");
timer.cancel();
}
}
public static void main(String args[]) {
System.out.println("About to schedule task.");
new MyTimeTaskTest(5);
System.out.println("Task scheduled.");
}
}