简单的Java定时器库
我需要具有以下功能的 Java 计时器代码:
- 设置代码片段(
Runnable
或类似的东西)在特定延迟(具有秒精度)后执行一次 - 更改现有计时器的延迟事实并取消计时器。
- 使用线程池(因此没有 java.util.Timer)
我考虑过使用 Quartz,但它似乎太大了。
有没有一个小型图书馆可以做到这一点?或者我真的可以使用 Quartz 吗?或者我如何使用 ScheduledExecutor
自己实现它?
I have need for timer code in Java with these features:
- Setting pieces of codes (
Runnable
or something like it) to execute once after a specific delay (with second precision) - Changing the delay of an existing timer after the fact and cancelling timers.
- Using a thread pool (so no
java.util.Timer
)
I've looked into using Quartz, but it appears to be simply too large.
Is there a smallish library that does this? Or can I actually use Quartz? Or how would I implement it myself, using ScheduledExecutor
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我并没有完全问这个问题,但你似乎唯一想要 Java 计时器没有提供的是线程池,虽然我从来没有抽出时间使用我得到的答案,但他们似乎解决了
我可以用 Timer 对象使程序饱和吗?
I didn't quite ask this question but the only thing you seem to want that Java timers aren't giving is thread pooling, and while I never got around to using the answers I got they seem to address that
Can I saturate a program with Timer objects?
看看这篇文章:Java Timer vs ExecutorService?
Look at this post : Java Timer vs ExecutorService?
看看:
http://download.oracle.com/javase /6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html
Look at:
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html