After this great question on how to Override Java System.currentTimeMillis, where Jon Skeet suggests to make use of a replaceable clock, I was thinking on how it could work with the Timer class.
// Clock() is replacing Date()
Date workTime = new Clock().plusSeconds(30).toDate();
Timer timer = new Timer();
timer.schedule(new ExampleClass(), workTime);
If clock's time is in the past, Timer()
will use the system clock and fire the method instantaneously even though, ideally, it would wait until Clock()
would give back a current time plus 30 seconds.
What's the best approach to dealing with this?
I was hopping for an answer a bit more practical than to keep overriding it all...