Simple Java timer library
I have 开发者_如何学Cneed 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
?
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?
Look at this post : Java Timer vs ExecutorService?
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); public ScheduledFuture<V> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit); public ScheduledFuture<V> scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit);
Look at: http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html
精彩评论