Ok, you could do something like:
long millisWithinSecond = System.currentTimeMillis() % 1000; Thread.sleep(1000 - millisWithinSecond);
It will not be accurate, mind you - you may need to repeat that a bit messy.
However, it would be better not to sleep at all. Could you introduce a "sleeping service" that will allow you to fake a dream in tests? (I rarely needed to do this, but I often entered fake watches to tell different times.) What is the purpose of sleeping in production code in general?
source share