简体   繁体   中英

Simple Java timer library

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 ?

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM