public class ReminderBeep {
Toolkit toolkit;
Timer timer;
public ReminderBeep(int seconds) {
toolkit = Toolkit.getDefaultToolkit();
timer = new Timer();
timer.schedule(new RemindTask(), seconds * 1000);
}
class RemindTask extends TimerTask {
public void run() {
toolkit.beep();
System.out.println("Time's up!");
// timer.cancel(); //Not necessary because we call System.exit
// Stops the AWT thread (and everything else)
}
}
public static void main(String args[]) {
System.out.println("About to schedule task.");
new ReminderBeep(5);
**strong text**
System.out.println("Task scheduled.");
}
}
如何在spring中自动调用方法或服务
发布于 2015-07-13 17:39:02
有两种方法可以做到这一点。
1) Using Quartz Scheduler Framework 2) Using annotation type scheduled点击链接,您将看到示例的详细信息
发布于 2015-07-13 17:14:21
我认为你可以使用@Schedule。
请查看此处的文档:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html
发布于 2015-07-13 17:20:53
Spring Framework提供了Scheduler,用于实现以下目标:
使用@Scheduled
注释:Link
https://stackoverflow.com/questions/31379417
复制相似问题