Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
按优先顺序排列:
Quartz 库(强烈推荐)。
java.util.Timer
。不如 Quartz 强大,但适合简单的工作。EJB 计时器服务。它的文档很少,它需要一个完整的 Java EE 容器,而且它实际上并没有做任何 Quartz 没有做的事情。
In order of preference:
The Quartz library (highly recommended).
java.util.Timer
. Not as powerful as Quartz, but good for simple jobs.The EJB timer service. It's poorly documented, it requires a full Java EE container, and it doesn't really do anything that Quartz doesn't.
查看 Timer 类
方法:
会让你做你想做的事。只要确保您使用的是正确的日期即可。
查看 API,您需要定义一个重载 run() 方法的 TimerTask。 run() 方法将包含您要调用的方法。
Check out the Timer Class
The method:
will allow you to do what you want. Just be sure you are using the correct date.
Looking at the API, you will need to define a
TimerTask
that overloads the run() method. The run() method will contain the method you want to call.如果你需要更健壮的东西,你也可以使用 Quartz 进行 Cron 之类的调度
If you need something more robust, you can also use Quartz for Cron like scheduling
这将获取当前日期和时间。
然后创建一个循环,每秒检查该函数,并使用 if 语句来执行您想要的代码,如果时间是您想要的时间。
This will get the current date and time.
Then make a loop that checks the function every second and use an if statement to execute the code you want if the time is the time you want.