0

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?

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301

3 Answers3

1

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?

Community
  • 1
  • 1
HahaHortness
  • 1,570
  • 1
  • 15
  • 16
1

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);
Community
  • 1
  • 1
Dead Programmer
  • 12,427
  • 23
  • 80
  • 112